方案一,Jackson
String json = objectMapperFace.writeValueAsString(contract);Map<String,Object> map = objectMapperFace.readValue(json, Map.class);
方案二 , apache BeanUtils
Map<String,String> beanMap = null;try {beanMap = BeanUtils.describe(contract);} catch (IllegalAccessException e) {throw new RuntimeException(e);} catch (InvocationTargetException e) {throw new RuntimeException(e);} catch (NoSuchMethodException e) {throw new RuntimeException(e);}
与Jackson的结果不同是因为我属性用了 @JsonIgnore 注解。
其他
- fastjson