英文:
How to deserialize n-dimensional json array of a given data type in java
问题
无法编写通用代码,可以使用库(如gson、jackson等)将这些表示张量数据的JSON反序列化为Java数组。
示例JSON1
{
"dim": [1, 4],
"type": "FP64",
"data": [[5.1, 3.5, 1.4, 0.2]]
}
Java对象- List<List<Float>>
示例JSON2
{
"dim": [4],
"type": "INT8",
"data": [0, 1, 2, 3]
}
Java对象- List<Integer>
示例JSON3
{
"dim": 1,
"type": "BYTES",
"data": ["This is a String"]
}
Java对象- List<String>
英文:
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>
答案1
得分: 1
你可以引入Maven依赖
<!--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>
然后你可以编写代码,然后合并数据。
我的英语不太好,但解决方案是可行的。
关于hutool,你可以参考https://github.com/dromara/hutool/blob/v5-master/README-EN.md
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论