我正在使用Jackson转换对象,包括数组对象到www.example.com文件,但转换数组对象时的结果看起来不像我预期的那样好。application.properties file but the result when convert array object look not good as I expected. This is my code:
JSONSerializer serializer = new JSONSerializer().rootName("application").prettyPrint(false);
String json = serializer.serialize(configDto.getValue());
ObjectMapper om = new ObjectMapper();
JsonNode tree = om.readTree(json);
Properties props;
JavaPropsMapper mapper = new JavaPropsMapper();
props = mapper.writeValueAsProperties(tree);
props.store(new FileOutputStream(file), "");
输入:
{
"nation": [
{
"key": "France"
},
{
"key": "Spain"
},
{
"key": "England"
}
],
"movie": "Avatar 2"
}
结果:
application.nation.1 = France
application.nation.2 = Spain
application.nation.3 = England
application.movie = Avatar 2
预期结果:
application.nation[1] = France
application.nation[2] = Spain
application.nation[3] = England
application.movie = Avatar 2
我怎样才能把数据转换成我期望的结果呢?对不起,我的英语不好!谢谢!
1条答案
按热度按时间rqqzpn5f1#
可能会在json数组中生成
nation
。对不起,我还没有测试过它。