0

Unable to write a generic code which can deserialize these json (represents tensor data) to java array using libraries like gson, jackson etc

example json1 { "dim": [1,4], "type": "FP64", "data": [[5.1,3.5,1.4,0.2]] }

Java object- List<List<<Float>>

example json2 { "dim": [4], "type": "INT8", "data": [0, 1, 2, 3] }

Java object - List<Integer>

example json3 { "dim": [1], "type": "BYTES", "data": ["This is a String"] }

Java object- List<String>

G.D
  • 305
  • 5
  • 18
  • 1
    "Unable to write a generic code"; can you please then show what you wrote so far and why it is not working? Do you know beforehand the type of the data, or do you have to determine it based on `dim` and `type`? Without more information about the specific problem you encountered, this is probably a duplicate: [Gson](https://stackoverflow.com/q/5554217), [Jackson](https://stackoverflow.com/q/11664894) – Marcono1234 Mar 08 '23 at 19:41

1 Answers1

1

You can introduce maven dependencies

<!--hutool-->
    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>5.7.17</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.66</version>
    </dependency>

Then you write the code enter image description here

Then combine the data.

My English is not good,But the solution is OK.

For hutool, you can see https://github.com/dromara/hutool/blob/v5-master/README-EN.md