0
我有叫ObjectMap的自定義地圖執行如下命令:如何使用jackson ObjectMapper將POJO映射到自定義地圖?
public class ObjectMap extends LinkedHashMap<String, Object> implements Serializable {
...
}
我可以使用傑克遜ObjectMapper如下任何POJO轉換爲該ObjectMap的:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(
objectMapper.getSerializationConfig().
getDefaultVisibilityChecker().
withFieldVisibility(JsonAutoDetect.Visibility.ANY).
withGetterVisibility(JsonAutoDetect.Visibility.NONE).
withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
);
ObjectMap objectMap = objectMapper.convertValue(object, new TypeReference<ObjectMap>() {});
但問題是,如果我的POJO複雜的領域被映射到一個LinkedHashMap而不是ObjectMap。那麼如何強制ObjectMapper將內部字段映射到ObjectMap而不是LinkedHashMap呢?