Java 有没有一种方法可以通过jackson读取json文件并创建readValue()中给出的对象以外的其他对象
简而言之,我想简化我的代码。现在,我将int的二维数组存储在一个json文件中。已正确读取并转换为二维精灵数组。但问题是,在大多数情况下,不到5%的int数组被转换器使用的数据填充 我宁愿为每个精灵提供一个字符串作为图像位置,并为它在精灵数组中的位置提供x和y坐标。这将使代码更易于阅读 极端情况: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
//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}
],