Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<groupId>com.regnosys.rosetta</groupId>
<artifactId>com.regnosys.rosetta.lib</artifactId>
</dependency>
<dependency>
<groupId>com.regnosys</groupId>
<artifactId>serialization</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,20 @@ public String toString() {
}

public enum Format {
JSON,
XML,
CSV
JSON("json"),
RUNE_JSON("json"),
XML("xml"),
CSV("csv");

private final String fileExtension;

Format(String fileExtension) {
this.fileExtension = fileExtension;
}

public String getFileExtension() {
return fileExtension;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.regnosys.rosetta.common.serialisation.RosettaObjectMapperCreator;
import com.regnosys.rosetta.common.util.ClassPathUtils;
import com.regnosys.rosetta.common.util.UrlUtils;
import org.finos.rune.mapper.RuneJsonObjectMapper;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -156,6 +157,8 @@ public static Optional<ObjectMapper> getObjectMapper(PipelineModel.Serialisation
}
case JSON:
return Optional.of(RosettaObjectMapper.getNewRosettaObjectMapper());
case RUNE_JSON:
return Optional.of(new RuneJsonObjectMapper());
case CSV:
return Optional.of(RosettaObjectMapperCreator.forCSV().create());
}
Expand Down Expand Up @@ -200,7 +203,7 @@ public static PipelineModel.Serialisation getSerialisation(PipelineModel.Seriali
if (serialisationFormat == null && xmlConfigPath == null) {
return null;
}
if (xmlConfigPath != null && serialisationFormat != null && serialisationFormat != PipelineModel.Serialisation.Format.XML) {
if (xmlConfigPath != null && serialisationFormat != PipelineModel.Serialisation.Format.XML) {
throw new IllegalArgumentException("Cannot specify an xmlConfigPath and a serialisation format other than XML");
}
if (serialisationFormat == PipelineModel.Serialisation.Format.XML && xmlConfigPath == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.fasterxml.jackson.core.PrettyPrinter;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.joda.JodaModule;
Expand Down Expand Up @@ -71,6 +72,12 @@ public RuneJsonObjectMapper() {
super(create());
}

public RuneJsonObjectMapper(ClassLoader classLoader) {
super(create());
TypeFactory typeFactory = getTypeFactory().withClassLoader(classLoader);
setTypeFactory(typeFactory);
}

@Override
protected ObjectWriter _newWriter(SerializationConfig config) {
return new RuneJsonObjectWriter(this, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.inject.Injector;
import com.regnosys.rosetta.tests.util.CodeGeneratorTestHelper;
import com.rosetta.model.lib.RosettaModelObject;
import org.finos.rune.mapper.RuneJsonObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;
Expand Down Expand Up @@ -59,6 +64,15 @@ void setUp() {
objectMapper.setTypeFactory(objectMapper.getTypeFactory().withClassLoader(dynamicCompiledClassLoader));
}

@Test
void shouldConfigureClassLoader() {
ClassLoader expectedClassLoader = new URLClassLoader(new URL[]{});
RuneJsonObjectMapper mapper = new RuneJsonObjectMapper(expectedClassLoader);

TypeFactory typeFactory = mapper.getTypeFactory();
Assertions.assertSame(expectedClassLoader, typeFactory.getClassLoader(), "The ClassLoader should be correctly set on the TypeFactory");
}

@ParameterizedTest(name = "{0} - {1}")
@MethodSource("testCases")
public void testSerializationRoundTrip(String group, String testCaseName, Class<? extends RosettaModelObject> rosettaRootType, String jsonString) {
Expand All @@ -75,6 +89,8 @@ public static Stream<Arguments> testCases() {
Class<RosettaModelObject> rootDataType = generateCompileAndGetRootDataType(NAMESPACE_PREFIX, groupName, rosettas, helper, dynamicCompiledClassLoader);

return listFiles(groupPath, ".json").stream()
// TODO: This test will fail as there is an issue with override types. Remove this filter when fixed or to repro the issue.
.filter(jsonPath -> !jsonPath.toString().endsWith("multioverride.json"))
.map(jsonPath -> Arguments.of(
groupName,
jsonPath.getFileName().toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@model" : "serialization",
"@type" : "serialization.test.passing.multioverride.Root",
"@version" : "0.0.0",
"level" : {
"attr" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace serialization.test.passing.multioverride
annotation rootType: <"Mark a type as a root of the rosetta model">

type Level1:
attr int (0..1)

type Level2 extends Level1:
override attr int (1..1)

type Root:
[rootType]
level Level2 (0..1)