java - How can I collapse Jackson encoding of a class to be encoding of one instance variable? -


i have set of classes 1 class has instance variable of class.

public class outer {     public inner inner; } public class inner {     public hashmap data; } 

i'm using jackson encode data structure json, , default, following encoding:

{ inner: { data: { : 1, b: 2 } } } // a:1,b:2 contents of data hashmap 

what need do[1] skip "data" layer in json maps - essentially, replacing encoding of inner class encoding of 1 of instance variables (hashmap data):

{ inner: { : 1, b: 2 } } 

what simplest way achieve this?

i'm assuming involve custom jackson encoder inner class unsure if that's easiest , best approach , if so, how write effectively.

notes:

  • just clear, inner class guaranteed have 1 encodable member (data). there other public members have @jsonignore annotation avoid encoding them.

  • the solution should not involve writing hand-built encoding code hashmap itself. used hashmap simplicity of example; in reality data of complex class hand-written encoder not feasible nor desirable.

  • only json encoding matters. no need matching decoder.

  • [1] avoid x-y problem types of answers/comments, requirement just, exactly, outlined. cannot change code reads json on other end , ignores data layer. cannot change class structure.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -