jackson deserialize array into a java object

前端 未结 2 1190
一生所求
一生所求 2021-01-20 21:53

I have json\'ed array of host, port, uri tuples encoded by 3rd party as an array of fixed length arrays:

[
  [\"www1.example.com\", \"443\", \"/         


        
相关标签:
2条回答
  • 2021-01-20 21:59

    Consider importing the two dimensional array and then running through a loop. Then you can have a constructor on the Endpoint class that accepts each instance of internal array.

    0 讨论(0)
  • 2021-01-20 22:23

    Add following annotation:

    @JsonFormat(shape=JsonFormat.Shape.ARRAY)
    class Endpoint {
    }
    

    and it should serialize entries as you wish.

    Also: it'd be safest to then use @JsonPropertyOrder({ .... } ) to enforce specific ordering, as JVM may or may not expose fields or methods in any specific order.

    0 讨论(0)
提交回复
热议问题