diff --git a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializer.java b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializer.java index 6b35c1454..b84626510 100644 --- a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializer.java +++ b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializer.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * Copyright (c) 2022 SAP SE or an SAP affiliate company * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,64 +28,29 @@ import java.util.stream.Collectors; import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.deserialization.EnumDeserializer; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.internal.ReflectionAnnotationIntrospector; import org.eclipse.digitaltwin.aas4j.v3.model.Environment; import org.eclipse.digitaltwin.aas4j.v3.model.Referable; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver; -import com.fasterxml.jackson.databind.module.SimpleModule; + +import static org.eclipse.digitaltwin.aas4j.v3.dataformat.json.ObjectMapperFactory.createMapper; +import static org.eclipse.digitaltwin.aas4j.v3.dataformat.json.ObjectMapperFactory.createTypeResolver; /** * Class for deserializing/parsing AAS JSON documents. */ public class JsonDeserializer { - - protected JsonMapper mapper; - protected SimpleAbstractTypeResolver typeResolver; - private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + protected ObjectMapper mapper; + protected final SimpleAbstractTypeResolver typeResolver; public JsonDeserializer() { - initTypeResolver(); - buildMapper(); - } - - protected void buildMapper() { - mapper = JsonMapper.builder() - .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) - .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) - .annotationIntrospector(new ReflectionAnnotationIntrospector()) - .addModule(buildEnumModule()) - .addModule(buildImplementationModule()) - .build(); - ReflectionHelper.JSON_MIXINS.entrySet().forEach(x -> mapper.addMixIn(x.getKey(), x.getValue())); - } - - @SuppressWarnings("unchecked") - private void initTypeResolver() { - typeResolver = new SimpleAbstractTypeResolver(); - ReflectionHelper.DEFAULT_IMPLEMENTATIONS - .stream() - .forEach(x -> typeResolver.addMapping(x.getInterfaceType(), x.getImplementationType())); - } - - protected SimpleModule buildEnumModule() { - SimpleModule module = new SimpleModule(); - ReflectionHelper.ENUMS.forEach(x -> module.addDeserializer(x, new EnumDeserializer<>(x))); - return module; - } - - protected SimpleModule buildImplementationModule() { - SimpleModule module = new SimpleModule(); - module.setAbstractTypes(typeResolver); - return module; + typeResolver = createTypeResolver(); + mapper = createMapper(typeResolver); } /** @@ -183,7 +149,7 @@ public Environment read(java.io.File file) throws FileNotFoundException, Deseria */ public void useImplementation(Class aasInterface, Class implementation) { typeResolver.addMapping(aasInterface, implementation); - buildMapper(); + mapper = createMapper(typeResolver); } /** @@ -374,4 +340,12 @@ public List readReferables(File src, Class outputCla public List readReferables(File src, Charset charset, Class outputClass) throws DeserializationException, FileNotFoundException { return readReferables(new FileInputStream(src), charset, outputClass); } + + public T read(String json, Class clazz) throws DeserializationException { + try { + return mapper.readValue(json, clazz); + } catch (JsonProcessingException ex) { + throw new DeserializationException("Error by deserializing the json string:\n" + json, ex); + } + } } diff --git a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializer.java b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializer.java index 750d83c8e..9f1e54285 100644 --- a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializer.java +++ b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializer.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * Copyright (c) 2022 SAP SE or an SAP affiliate company * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,59 +16,33 @@ */ package org.eclipse.digitaltwin.aas4j.v3.dataformat.json; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.serialization.EnumSerializer; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.internal.ReflectionAnnotationIntrospector; import org.eclipse.digitaltwin.aas4j.v3.model.Environment; import org.eclipse.digitaltwin.aas4j.v3.model.Referable; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.Objects; +import com.fasterxml.jackson.databind.ObjectMapper; /** * Class for serializing an instance of AssetAdministrationShellEnvironment or Referables to JSON. */ public class JsonSerializer { - - protected JsonMapper mapper; - private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + protected final ObjectMapper mapper; public JsonSerializer() { - buildMapper(); - } - - protected void buildMapper() { - mapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT) - .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) - .serializationInclusion(JsonInclude.Include.NON_NULL) - .addModule(buildEnumModule()) - .annotationIntrospector(new ReflectionAnnotationIntrospector()) - .build(); - ReflectionHelper.JSON_MIXINS.entrySet().forEach(x -> mapper.addMixIn(x.getKey(), x.getValue())); - } - - protected SimpleModule buildEnumModule() { - SimpleModule module = new SimpleModule(); - module.addSerializer(Enum.class, new EnumSerializer()); - return module; + mapper = ObjectMapperFactory.createMapper(); } /** @@ -214,4 +189,15 @@ public JsonNode toNode(Collection referables) { } return mapper.valueToTree(referables); } + + public String write(Object aas_element) throws SerializationException { + try { + // the new schema (version 3.0.RC02) defines modelType as a string, therefore the ModelTypeProcessor is not needed anymore + //return mapper.writeValueAsString(ModelTypeProcessor.postprocess(this.mapper.readTree(json))); + return mapper.writeValueAsString(aas_element); + } catch (JsonProcessingException ex) { + throw new SerializationException("Error serializing an aas-element", ex); + } + } + } diff --git a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ObjectMapperFactory.java b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ObjectMapperFactory.java new file mode 100644 index 000000000..6a0ae0dd9 --- /dev/null +++ b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ObjectMapperFactory.java @@ -0,0 +1,97 @@ +package org.eclipse.digitaltwin.aas4j.v3.dataformat.json; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver; +import com.fasterxml.jackson.databind.module.SimpleModule; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.deserialization.EnumDeserializer; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.serialization.EnumSerializer; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper; + +/** + * This class contains the initialization code used by the JsonSerializer and JsonDeserializer. It also contains a + * factory method, that is very useful to be used in SpringBoot environment, to automate the serialization. Here is a + * sample code: + *
+ * {@code @Configuration}
+ * public class JacksonConfig {
+ *     {@code @Bean}
+ *     {@code @Primary}
+ *     public ObjectMapper objectMapper() {
+ *         return ObjectMapperFactory.createMapper();
+ *     }
+ *  
+ * Having such JacksonConfig class in your SpringBoot web application, the framework will always use the created mapper + * for serialization and deserialization, and you don't need to carry about it anymore. + */ +public class ObjectMapperFactory { + private ObjectMapperFactory() {} + + /** + * The factory method to create the object mapper for serialization/deserialization of AAS objects. + * @return the configured object mapper. According to the Jackson documentation the ObjectMapper class is + * thread-safe. + * + * The returned object mapper can be used directly for AAS serialization/deserialization, or you can use the utility + * JsonSerializer and JsonDeserializer wrapper classes. + */ + public static ObjectMapper createMapper() { + return createMapper(null); + } + + /** + * A package-private method used by JsonDeserializer wrapper class. It is needed only to support its + * useImplementation method, which require modification of the type resolver. + * @param typeResolver The type resolver used for deserialization. + * @return the configured object mapper. According to the Jackson documentation the ObjectMapper class is + * thread-safe. + */ + static ObjectMapper createMapper(SimpleAbstractTypeResolver typeResolver) { + ObjectMapper mapper = JsonMapper.builder() + .enable(SerializationFeature.INDENT_OUTPUT) + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .serializationInclusion(JsonInclude.Include.NON_NULL) + .serializationInclusion(JsonInclude.Include.NON_EMPTY) + .annotationIntrospector(new ReflectionAnnotationIntrospector()) + .addModule(buildEnumModule()) + .addModule(buildTypeResolverModule(typeResolver)) + .build(); + ReflectionHelper.JSON_MIXINS.entrySet().forEach(x -> mapper.addMixIn(x.getKey(), x.getValue())); + return mapper; + } + + /** + * A package-private method, to create a type resolver, which is used for serialization/deserialization of AAS + * object. + * @return the type resolver. + */ + static SimpleAbstractTypeResolver createTypeResolver() { + SimpleAbstractTypeResolver typeResolver = new SimpleAbstractTypeResolver(); + ReflectionHelper.DEFAULT_IMPLEMENTATIONS + .stream() + .forEach(x -> typeResolver.addMapping(x.getInterfaceType(), x.getImplementationType())); + return typeResolver; + } + + private static SimpleModule buildTypeResolverModule(SimpleAbstractTypeResolver typeResolver) { + final SimpleModule module = new SimpleModule(); + if(typeResolver == null) { + typeResolver = createTypeResolver(); + } + module.setAbstractTypes(typeResolver); + return module; + } + + private static SimpleModule buildEnumModule() { + SimpleModule module = new SimpleModule(); + ReflectionHelper.ENUMS.forEach(x -> { + module.addDeserializer(x, new EnumDeserializer<>(x)); + module.addSerializer(x, new EnumSerializer()); + }); + return module; + } +} diff --git a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/internal/ReflectionAnnotationIntrospector.java b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospector.java similarity index 93% rename from dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/internal/ReflectionAnnotationIntrospector.java rename to dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospector.java index 7aa2d6560..258bba1db 100644 --- a/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/internal/ReflectionAnnotationIntrospector.java +++ b/dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospector.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * Copyright (C) 2023 SAP SE or an SAP affiliate company. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.eclipse.digitaltwin.aas4j.v3.dataformat.json.internal; +package org.eclipse.digitaltwin.aas4j.v3.dataformat.json; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonTypeInfo; @@ -31,7 +32,7 @@ import java.util.stream.Collectors; /** - * This class helps to dynamically decide how to de-/serialize classes and + * This utility class has package-private visibility and helps to dynamically decide how to de-/serialize classes and * properties defined in the AAS model library. * * This is equivalent to adding the following annotations @@ -52,7 +53,7 @@ * * */ -public class ReflectionAnnotationIntrospector extends JacksonAnnotationIntrospector { +class ReflectionAnnotationIntrospector extends JacksonAnnotationIntrospector { private static final long serialVersionUID = 1L; @@ -108,5 +109,4 @@ public JsonInclude.Value findPropertyInclusion(Annotated a) { } return result; } - } diff --git a/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializerTest.java b/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializerTest.java index 6fe6d1140..efb511cbe 100644 --- a/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializerTest.java +++ b/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonDeserializerTest.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * Copyright (c) 2022 SAP SE or an SAP affiliate company * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +47,14 @@ public void testSimpleExample() throws Exception { Assert.assertEquals(expected, actual); } + @Test + public void testSimpleExampleDirectly() throws Exception { + ObjectMapper mapper = ObjectMapperFactory.createMapper(); + Environment expected = Examples.EXAMPLE_SIMPLE.getModel(); + Environment actual = mapper.readValue(Examples.EXAMPLE_SIMPLE.fileContentStream(), Environment.class); + Assert.assertEquals(expected, actual); + } + @Test public void testFullExample() throws Exception { Environment expected = Examples.EXAMPLE_FULL.getModel(); @@ -61,6 +70,14 @@ public void testFullExampleFromNode() throws Exception { Assert.assertEquals(expected, actual); } + @Test + public void testFullExampleDirectly() throws Exception { + ObjectMapper mapper = ObjectMapperFactory.createMapper(); + Environment expected = Examples.EXAMPLE_FULL.getModel(); + Environment actual = mapper.readValue(Examples.EXAMPLE_FULL.fileContentStream(), Environment.class); + Assert.assertEquals(expected, actual); + } + @Test public void testCustomImplementationClass() throws Exception { String json = new JsonSerializer().write(AASSimple.createEnvironment()); diff --git a/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializerTest.java b/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializerTest.java index 7b51487f1..a34404e7f 100644 --- a/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializerTest.java +++ b/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonSerializerTest.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * Copyright (c) 2022 SAP SE or an SAP affiliate company * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +17,7 @@ package org.eclipse.digitaltwin.aas4j.v3.dataformat.json; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.File; @@ -24,12 +26,16 @@ import java.util.List; import java.util.Set; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException; import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.AASSimple; import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.util.ExampleData; import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.util.Examples; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.eclipse.digitaltwin.aas4j.v3.model.Environment; import org.eclipse.digitaltwin.aas4j.v3.model.Referable; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetInformation; import org.json.JSONException; import org.junit.Rule; import org.junit.Test; @@ -51,12 +57,19 @@ public class JsonSerializerTest { public TemporaryFolder tempFolder = new TemporaryFolder(); @Test - public void testSerializeNull() throws JsonProcessingException, IOException, SerializationException { + public void testSerializeNull() throws SerializationException { assertEquals("null", new JsonSerializer().write((Environment) null)); } @Test - public void testWriteToFile() throws JsonProcessingException, IOException, SerializationException { + public void testDirectSerializeNull() throws JsonProcessingException { + ObjectMapper mapper = ObjectMapperFactory.createMapper(); + String json = mapper.writeValueAsString((Environment)null); + assertEquals("null", json); + } + + @Test + public void testWriteToFile() throws IOException, SerializationException { File file = tempFolder.newFile("output.json"); new JsonSerializer().write(file, AASSimple.createEnvironment()); assertTrue(file.exists()); @@ -67,11 +80,20 @@ public void testSerializeEmpty() throws JsonProcessingException, IOException, Se validateAndCompare(Examples.ENVIRONMENT_EMPTY); } + @Test + public void testSerializeDirectEmpty() throws IOException, JSONException { + validateAndCompareDirectly(Examples.ENVIRONMENT_EMPTY); + } + @Test public void testSerializeSimpleExample() throws SerializationException, JSONException, IOException { validateAndCompare(Examples.EXAMPLE_SIMPLE); } + public void testSerializeDirectlySimpleExample() throws SerializationException, JSONException, IOException { + validateAndCompareDirectly(Examples.EXAMPLE_SIMPLE); + } + @Test public void testSerializeFullExample() throws SerializationException, JSONException, IOException { validateAndCompare(Examples.EXAMPLE_FULL); @@ -92,6 +114,53 @@ public void testSerializeEmptyReferableList() throws SerializationException { assertEquals("[]", serialized); } +// @Test +// public void testSerializeEmptyReferableList() throws SerializationException, JSONException { +// List emptyList = Collections.emptyList(); +// String serialized = new JsonSerializer().write(emptyList); +// JSONAssert.assertEquals("[]", serialized, JSONCompareMode.NON_EXTENSIBLE); +// } + + @Test + public void testSerializeDirectlyFullExample() throws SerializationException, JSONException, IOException { + validateAndCompareDirectly(Examples.EXAMPLE_FULL); + } + + @Test + public void testSerializeAssetInfo() throws SerializationException, DeserializationException { + AssetInformation assetInfo = new DefaultAssetInformation.Builder() + .assetKind(AssetKind.INSTANCE) + .assetType("asset-type") + .globalAssetID("global-asset-id").build(); + String jsonString = new JsonSerializer().write(assetInfo); + assertNotNull(jsonString); + AssetInformation assetInfo2 = new JsonDeserializer().read(jsonString, AssetInformation.class); + assertNotNull(assetInfo2); + assertEquals(assetInfo, assetInfo2); + } + + @Test + public void testDirectlySerializeAssetInfo() throws JsonProcessingException { + AssetInformation assetInfo = new DefaultAssetInformation.Builder() + .assetKind(AssetKind.INSTANCE) + .assetType("asset-type") + .globalAssetID("global-asset-id").build(); + ObjectMapper mapper = ObjectMapperFactory.createMapper(); + String jsonString = mapper.writeValueAsString(assetInfo); + assertNotNull(jsonString); + AssetInformation assetInfo2 = mapper.readValue(jsonString, AssetInformation.class); + assertNotNull(assetInfo2); + assertEquals(assetInfo, assetInfo2); + } + + @Test + public void testDirectlySerializeEmptyReferableList() throws JsonProcessingException, JSONException { + List emptyList = Collections.emptyList(); + ObjectMapper mapper = ObjectMapperFactory.createMapper(); + String serialized = mapper.writeValueAsString(emptyList); + JSONAssert.assertEquals("[]", serialized, JSONCompareMode.NON_EXTENSIBLE); + } + private void validateAndCompare(ExampleData exampleData) throws IOException, SerializationException, JSONException { String expected = exampleData.fileContent(); String actual = new JsonSerializer().write(exampleData.getModel()); @@ -106,4 +175,13 @@ private void validateAndCompare(String expected, String actual) throws IOExcepti JSONAssert.assertEquals(actual, expected, JSONCompareMode.NON_EXTENSIBLE); } + private void validateAndCompareDirectly(ExampleData exampleData) throws IOException, JSONException { + String expected = exampleData.fileContent(); + ObjectMapper mapper = ObjectMapperFactory.createMapper(); + String actual = mapper.writeValueAsString(exampleData.getModel()); + Set errors = new JsonSchemaValidator().validateSchema(actual); + assertTrue(errors.isEmpty()); + JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(actual, expected, JSONCompareMode.NON_EXTENSIBLE); + } } diff --git a/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospectorTest.java b/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospectorTest.java index a020dd4a9..e391295a6 100644 --- a/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospectorTest.java +++ b/dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/ReflectionAnnotationIntrospectorTest.java @@ -27,7 +27,6 @@ import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.CustomSubProperty; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.CustomSubmodel; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.CustomSubmodel2; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.internal.ReflectionAnnotationIntrospector; import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.mixins.ReferenceMixin; import org.junit.Before; import org.junit.Test; diff --git a/dataformat-xml/pom.xml b/dataformat-xml/pom.xml index 4ed49f74a..3975d594d 100644 --- a/dataformat-xml/pom.xml +++ b/dataformat-xml/pom.xml @@ -72,4 +72,18 @@ jackson-core + + + + org.apache.maven.plugins + 2.22.2 + maven-surefire-plugin + + + **/TestSuite*.java + + + + + diff --git a/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/TestSuite.java b/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/TestSuite.java new file mode 100644 index 000000000..c8948f2d0 --- /dev/null +++ b/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/TestSuite.java @@ -0,0 +1,15 @@ +package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses( + { + XmlValidationTest.class, + XMLDeserializerTest.class, + XmlSerializerTest.class, + } +) +public class TestSuite { +} diff --git a/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java b/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java index 8da48bc62..985054436 100644 --- a/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java +++ b/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java @@ -123,7 +123,7 @@ public void deserializeAASFullConceptDescription() throws FileNotFoundException, @Test public void deserializeAASWithExtensionMinimal() throws SerializationException, SAXException, FileNotFoundException, DeserializationException { Environment env = new XmlDeserializer().read(XmlSerializerTest.AAS_WITH_EXTENSION_MINIMAL); - + //String xml = new XmlSerializer().write(env); Assert.assertEquals(Examples.EXTENSION_MINIMAL, env); }