Open io7m opened 2 years ago
+1, right now just writing Deserializers, but hoping there will be a better way at some point
Wrong repo since there's XML-specific parts.
However, I doubt this can be implemented -- problem being that POJOs like LocationID
cannot really be included as attributes in general; there is no support for that by default.
Although I guess one thing I would try to add in LocationID
would be something like:
// Inside Record definition:
@JsonValue
public String serialization() {
return id.toString()
}
which would explicitly serialize LocationId as String
and then it should be possible to serialize as an XML attribute.
Also if needing deserialization will probably need to specify @JsonCreator(mode = Mode.DELEGATING)
to get single-String argument bound properly.
Is your feature request related to a problem? Please describe.
The following example code uses a trivial wrapper record (
LocationID
) to allow some extra type-safety when working with elements declared in an existing schema:The output of the program ends up as:
The desired output can be produced with the following definitions instead:
But it's slightly unfortunate that the definitions have to be declared in this way, because we lose a lot of the nice properties of
record
classes in the process.Describe the solution you'd like
I'd like to be able to use records instead of POJOs in the above example.
Usage example
See above. :slightly_smiling_face:
Additional context
See this thread on the mailing list: https://groups.google.com/d/msgid/jackson-user/20210911172814.62fd2925%40sunflower.int.arc7.info