需要加上配置,不然解析会失败,产生一个空对象
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);// 忽略大小写
代码:
public class StreamingJob { public static void main(String[] args) throws Exception { final Logger logger = LoggerFactory.getLogger(StreamingJob.class); ObjectMapper objectMapper = new ObjectMapper(); String order_attrs1 = "[{\"cust_ORDER_ID\":1000,\"remark\":\"这是一个备注\"}]"; String order_attrs2 = "[{\"CUST_ORDER_ID\":1000,\"REMARK\":\"这是一个备注\"}]";
// 配置忽略大小写 objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); List<OrderAttr> itemList = objectMapper.readValue(order_attrs2, new TypeReference<List<OrderAttr>>() { }); logger.info("解析:{}", itemList.size()); } }
引入的pom
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.13.0</version> </dependency>
标签:jackson,String,Flink,databind,ObjectMapper,order,objectMapper From: https://www.cnblogs.com/sunAnqing/p/18206636