Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有没有一种方法可以通过jackson读取json文件并创建readValue()中给出的对象以外的其他对象_Java_Arrays_Json_Jackson - Fatal编程技术网

Java 有没有一种方法可以通过jackson读取json文件并创建readValue()中给出的对象以外的其他对象

Java 有没有一种方法可以通过jackson读取json文件并创建readValue()中给出的对象以外的其他对象,java,arrays,json,jackson,Java,Arrays,Json,Jackson,简而言之,我想简化我的代码。现在,我将int的二维数组存储在一个json文件中。已正确读取并转换为二维精灵数组。但问题是,在大多数情况下,不到5%的int数组被转换器使用的数据填充 我宁愿为每个精灵提供一个字符串作为图像位置,并为它在精灵数组中的位置提供x和y坐标。这将使代码更易于阅读 极端情况: //spriteLayerOne is now initialized at another point before this is ever called @JsonProperty(value

简而言之,我想简化我的代码。现在,我将int的二维数组存储在一个json文件中。已正确读取并转换为二维精灵数组。但问题是,在大多数情况下,不到5%的int数组被转换器使用的数据填充

我宁愿为每个精灵提供一个字符串作为图像位置,并为它在精灵数组中的位置提供x和y坐标。这将使代码更易于阅读

极端情况:

//spriteLayerOne is now initialized at another point before this is ever called
@JsonProperty(value = "fillSpriteLayerOne")
private void fillSpriteLayerOne(String resourceLocation, int x, int y) {
    spriteLayerOne[y][x] = new Sprite(resourceLocation);
}
private void setSpriteLayerOne(int[]]spriteLayer){
spriteLayerOne=新精灵[tileMap.length][tileMap[0.length];
for(int i=0;i
理想情况:

//spriteLayerOne is now initialized at another point before this is ever called
@JsonProperty(value = "fillSpriteLayerOne")
private void fillSpriteLayerOne(String resourceLocation, int x, int y) {
    spriteLayerOne[y][x] = new Sprite(resourceLocation);
}

如果添加库是一个选项,则可能需要查看
ModelMapper
。如果添加库是一个选项,则可能需要查看
ModelMapper
"fillSpriteLayerOne" : [
    {"player_between", 2, 1}
],