Jaskson treats complex extensive target

Jaskson treats complex extensive target

Jackson is a Json series that is used extensively in Java system change and turn over alignment to convert kind of warehouse, it offerred rich API to be used to developer.

The record falls to use Jackson to handle the result of complex extensive object recently today, its core uses TypeFactory.constructParametricType() method namely, from inside Type constructs according to this outside arriving.

  • Example 1: List<Map<String, person>>
  • Example 2: Map<String, list<Person>>

    Example 1: List<Map<String, person>>

    Assume I have an object List<Map<String, person>> , I construct first the object turns next for string.

    Jaskson treats complex extensive target

    Turn over its alignment to change next:

    Jaskson treats complex extensive target

    Change be meeting newspaper fault so directly!

    The kind that needs to use TypeFactory.constructParametricType() to undertake JavaType is tectonic: LIst<Map<String, person>>

    Those who need an attention is, need when construct from inside construction undertakes outside arriving:

    1. Construct first Map<String, person> gets InnerType
    2. Reframe List<innerType>

    Code is shown as follows:

    Jaskson treats complex extensive target

    The proposal uses actual subclass model will replace: For instance Map is HashMap accurately, list is actual ArrayList accurately.

    Example 2: Map<String, list<Person>>Jaskson treats complex extensive target

    Here has place of a little knowledge, watchful is parameter type should match: COnstructParametricType method is like below 2 kinds of statement to need to notice:

    Jaskson treats complex extensive target

    The from the back alterable form in the method joins parameter to must agree.

    Can examine return profit the reframe overall situation of 2, I am a hope originally:

    Jaskson treats complex extensive target

    But IDE clew parameter does not match, examining seriously is really: One is Class, one is JavaType.

    Solve this problem through direct GetRawClass so:

    Jaskson treats complex extensive target

    Epilogue

    Core train of thought: From inside the type constructs outside arriving, one step comes!

    Achieve formerly not easy, acknowledgment attention, comment, transmit, collect!

  • 未经允许不得转载:News » Jaskson treats complex extensive target