-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Story/1045/cdm serialization #446
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pom.xml
Outdated
@@ -87,14 +91,13 @@ | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<java.enforced.version>[17,18)</java.enforced.version> | |||
<maven.compiler.release>8</maven.compiler.release> | |||
<rosetta.dsl.version>9.25.0</rosetta.dsl.version> | |||
<rosetta.dsl.version>0.0.0.main-SNAPSHOT</rosetta.dsl.version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DSL version
serialization/src/test/resources/rune-serializer-round-trip-test/data/data-types.json
Show resolved
Hide resolved
hugohills-regnosys
approved these changes
Jan 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Custom Serializer/Deserializer for Rune DSL Common Library
Overview
This change introduces a custom JSON serializer and deserializer for the Rune DSL Common Library. The primary goal is to ensure JSON serialization and deserialization that:
The following specification has been followed when Implementing these changes Serialization Specification v0.9.pdf
Benefits to Users
High-Level Summary of the Development Approach
The
RuneJJsonObjectMapper
serves as the core component, offering pre-configured behaviour to ensure JSON output aligns closely with the structure of the DSL.The implementation of the
RuneJsonObjectMapper
andRuneJsonObjectWriter
provides a specialized solution for JSON serialization and deserialization tailored to the Rune DSL.To enrich the JSON output with contextual information, the
RuneJsonObjectWriter
extends Jackson’sObjectWriter
. It adds top-level metadata, such as model name, type, and version, derived from annotations on the serialized objects.Additionally, there are three annotations relied upon by the
RuneJsonAnnotationIntrospector
to customize the serialized structure. TheRuneJsonAnnotationIntrospector
is responsible for scanning the annotations on the generated Rune DSL POJOs and determining how they should be applied during both serialization and deserialization. It recognizes the following annotations:@RuneDataType
: Captures key details about the object, such as its canonical type name, model name and version. This information is then injected into the top-level JSON metadata during serialization.@RuneAttribute
: Marks specific fields within the object as attributes, guiding how they are serialized to ensure they align with the DSL's structure.@RuneMetaType
: Indicates when nodes with an extra wrapping layer (originating from the underlying Java POJO) should be unwrapped during serialization, ensuring that the resulting JSON structure is clean and free of unnecessary nesting.These annotations collectively ensure that the serialized JSON output reflects both the structure and semantics of the Rune DSL. See finos/rune-dsl#889 for annotation implementation details.
Findings
Property ordering can't be overridden when using JSON unwrapping functionality, see jackson-databind issue 1670 for further details.
Top level meta types are not straight forward due to not being aware of when you are processing a top level type in Jackson. This solution achieves this by overriding the ObjectMapper and ObjectWriter
The specification for
@key:scoped
requires that we go from an array structure in the old world to a single element in the new world:Existing
New
This has been achieved by adding new getters/setters to
com.rosetta.model.metafields.MetaFields
in the DSL. These new methods are only annotated with the new@RuneAttribute
annotations and add a single item to the underlying data structure. See Rune DSL PR 899The dynamically generated and compiled test
.rosetta
files is done inside theRuneSerializerTestHelper.generateCompileAndGetRootDataType()
method using an already existingCodeGeneratorTestHelper
utility. There is a problem in that the generated classes are not visible to the Jackson mapper used in the test. Upon investigation it looked like this is a class loader issue that I was not able to get to the bottom of quickly. As a work around I've stored the generated classes inside a test class calledDynamicCompiledClassLoader
which is handed of to the mapper. It may be worth investigating this further in case the issue is not only isolated to the tests.Although not relevant for this change this work has highlighted a problem in the current
RosettaObjectMapper
regarding setting multi cardinality values. The mapper is currently relying on a legacy fallbackLegacyRosettaBuilderIntrospector
in order to be able to set multi cardinality values correctly. On investigation it looks like the reason for this is due to the@RosettaAttribute
annotation having been moved fromset(List<Foo> ...)
methods toadd(Foo ...)
methods which Jackson is not able to work with natively. This change adds the new@RuneAttribute
annotation back to the setter methods which means the newRuneJacksonJsonObjectMapper
requires no legacy fallback.Follow Up Tasks