List-JSON互转

1、List转JSON
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Inclusion.NON_NULL);
mapper.setSerializationInclusion(Inclusion.NON_EMPTY);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
System.out.println("{\"button\": "+objectMapper.writeValueAsString(buttons)+"}");

2、JSON转List
ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
JPCallback jpCallback = mapper.readValue(target,JPCallback.class);

猜你喜欢

转载自wgbaoweii.iteye.com/blog/2287202
今日推荐