1

I have a requirement to take a document with ~60 fields and map it to a customer schema. Our schema has one field that I have as an array like so:

  "documents": [{
    "type": "Resume",
    "url": "https://.s3.amazonaws.com/F58723BD-6148-E611-8110-000C29E6C08D.txt"
  }, {
    "type": "Reference",
    "url": "https://.s3.amazonaws.com/F58723BD-6148-E611-8110-000C29E6C08D.txt"
  }]

I need to transform that to:

"document1": {"type":"Resume", "https://.s3.amazonaws.com/F58723BD-6148-E611-8110-000C29E6C08D.txt"}
"document2": {"type":"Reference", "url":"https://.s3.amazonaws.com/F58723BD-6148-E611-8110-000C29E6C08D.txt"}

I've started a cumstom serializer but would really, really like to not have to write a custom serializer for all 60 fields to just do that one transform. Is there a way to tell jackson to serialize all other fields as normal and use my logic for just this one instance?

I have tried a number of options and keep getting the ever-so-helpful error:

com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value

If I could even determine what this means it would be greatly helpful.

Thanks in advance!

RockyMountainHigh
  • 2,871
  • 5
  • 34
  • 68

2 Answers2

0

A possible solution is to have the cumstom serializer call the default serializer for all those fields that can undergo default serialization.
See this thread for how to do it How to access default jackson serialization in a custom serializer

Community
  • 1
  • 1
Sharon Ben Asher
  • 13,849
  • 5
  • 33
  • 47
0

If you create, from the input, a map where the values are a string with raw Json, you can use the custom serializer written by Steve Kuo in Jackson @JsonRawValue for Map's value

Community
  • 1
  • 1
Franjavi
  • 647
  • 4
  • 14