Tag: jackson

在springboot反序列化器中包含带jackson的root对象

如何将我的jackson反序列化器中的objeto root包含在spring-boot中? 我尝试放入application.properties spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true 我尝试使用一个配置器 @Configuration public class JacksonConfig { @Bean public Jackson2ObjectMapperBuilder jacksonBuilder() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.featuresToEnable(DeserializationFeature.UNWRAP_ROOT_VALUE); builder.indentOutput(true).dateFormat(new SimpleDateFormat(“dd/MM/yyyy HH:mm:ss”)); builder.indentOutput(true); return builder; } } 我把注释放在我的classe中 @JsonRootName(“contato”) public class TbContato extends EntityBase { 但是没有工作我得到了这个回报: { “cdContato”: 12, “dtContato”: “03/08/2015 16:04:43”, “cdUsuario”: null, “nmParte”: “Fabio Ebner”, “nmEmailParte”: “fabioebner@gmail.com”, “nmAssunto”: “Assuntttoooo”, “dsMensagem”: “mensagem […]

在Jackson中序列化/反序列化自定义Map

我有一个非常简单的Map我希望在Jackson中序列化和反序列化,但我无法让它工作。 我尝试过以下方法: @JsonSerialize(keyUsing=TurnKeySerializer.class) @JsonDeserialize(keyUsing = TurnKeyDeserializer.class) Map publicTurns = new TreeMap(); @JsonIgnoreProperties(ignoreUnknown = true) @Data //Creates Getter/Setter etc public class TurnKey implements Comparable { private final int turnNumber; private final String username; public TurnKey(int turnNumber, String username) { this.turnNumber = turnNumber; this.username = username; } @Override public int compareTo(TurnKey o) { int v = Integer.valueOf(turnNumber).compareTo(o.getTurnNumber()); […]

如何比较JSON文档并返回与Jackson或Gson的差异?

我正在使用spring-boot来开发后端服务。 有一种方案可以比较2-beans(一个是DB对象,另一个是客户端请求的对象)并返回“new element”,“modified element”,如果没有更改,则返回false。 2豆的格式如下 “sampleList”:{ “timeStamp”:”Thu, 21 Jun 2018 07:57:00 +0000″, “id”:”5b19441ac9e77c000189b991″, “sampleListTypeId”:”type001″, “friendlyName”:”sample”, “contacts”:[ { “id”:”5b05329cc9e77c000189b950″, “priorityOrder”:1, “name”:”sample1″, “relation”:”Friend”, “sampleInfo”:{ “countryCode”:”91″, “numberType”:”MOBILE”, “numberRegion”:”IN” } }, { “id”:”5b05329cc9e77c000189b950″, “priorityOrder”:1, “name”:”sample2″, “relation”:”Friend”, “sampleInfo”:{ “countryCode”:”91″, “numberType”:”MOBILE”, “numberRegion”:”IN” } } ] } 我在java中浏览了关于这种情况的bean比较的网络,但我找不到任何更简单的解决方案,但找到了一些很酷的JSON解决方案。 我可以看到GSON的一些解决方案,但它不会返回客户端对象包含“新元素”和“更改元素”。 有没有办法在JSON或JAVA中返回更新和修改过的元素? 你的帮助应该是值得的。 即使是暗示对我来说也是一个很好的开始。

Camel + Jackson:为所有反序列化注册一个模块

我正在使用Camel作为我的应用程序,消息作为JSON进入路由。 我使用JACKSON作为我的反序列化器。 我有一个案例,我需要一个自定义序列化器/反序列化器来处理我的一条消息。 我想要做的是为键注册自定义序列化器/解串器。 在Camel中,如何在我的路线中编组/取消编组时,如何确保序列化器/解串器可用?

如何为jackson编写一个全能(de)序列化器

如果事先知道类型,编写自定义序列化程序非常简单。 例如。 MyType可以写一个MyTypeSerializer extends StdSerializer 。 请参阅http://wiki.fasterxml.com/JacksonHowToCustomSerializers 但是,让我们说: 我有几种类型(接口)的对象通过jackson序列化。 我事先并不知道这些对象的类型。 我无法在这些类型上添加注释。 所有这些objets都可以转换为我知道的常见类型,以便我可以获取其状态数据,键入不属于其界面的类型。 这意味着我需要编写一个应该处理所有类型的串行器(“catch-all”)并且可以决定它是否支持它(4.)。 我天真地尝试过CatchAllSerializer extends StdSerializer但它根本没有被触发。 如何编写/注册将捕获所有类型的序列化程序,可以决定它是否支持给定类型并提供序列化机制?

如何使用jackson遍历生成的json模式并将自定义属性放在json模式中

{ “type”: “object”, “properties”: { “name”: { “type”: “string” }, “id”: { “type”: “string” }, “i”: { “type”: “integer” }, “p”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “id”: { “type”: “string” }, “i”: { “type”: “integer” }, “p1”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “id”: { “type”: […]

Jackson序列化的动态属性名称

我有很多类,我正在尝试序列化为JSON。 它们非常相似,所以我想知道是否有更好的方法来执行此操作,而不是每次出现此模式时创建3个非常接近相同的类: public class SomethingFoo { @JsonProperty(“foo”) Identifier foo // other properties } public class SomethingBar { @JsonProperty(“bar”) Identifier bar // other properties } public class SomethingBaz { @JsonProperty(“baz”) Identifier baz // other properties } 标识符是一个只包含一个字段的类: public class Identifier { @JsonProperty(“name”) String name = “”; } 我想做的是将标识符更改为: public class Identifier { @JsonProperty(“name”) String name = […]

如何在没有JAXBElement包装的情况下JSON-marshal JAXBElement包装的响应?

我有一个使用Spring(v4.0.5)的http服务。 它的http端点是使用Spring Web MVC配置的。 响应是由模式生成的JAXB2-anotated类。 响应包装在JAXBElement因为生成的JAXB类没有运行@XmlRootElement注释(并且架构无法修改为医生)。 我不得不通过XML编组来解决这个问题。 无论如何,它正在发挥作用。 现在我正在设置JSON编组。 我遇到的是获取具有JAXBElement “信封”的JSON文档。 { “declaredType”: “io.github.gv0tch0.sotaro.SayWhat”, “globalScope”: true, “name”: “{urn:io:github:gv0tch0:sotaro}say”, “nil”: false, “scope”: “javax.xml.bind.JAXBElement$GlobalScope”, “typeSubstituted”: false, “value”: { “what”: “what”, “when”: “2014-06-09T15:56:46Z” } } 我想要编组的只是value : { “what”: “what”, “when”: “2014-06-09T15:56:46Z” } 这是我的JSON编组配置(弹簧上下文配置的一部分): 我希望通过配置ObjectMapper可以实现这一点。 我想也可以推出我自己的序列化器。 思考? 建议?

使用jackson序列化时有条件地跳过对象

我有一个类似的课程 interface IHideable { boolean isHidden(); } class Address implements IHideable { private String city; private String street; private boolean hidden; } class PersonalInfo implements IHideable { private String name; private int age; private boolean hidden; } 我想在我的网络服务中序列化IHideable列表; 但过滤掉隐藏字段设置为true的任何对象。 基本上给出一个像对象的列表 [ {‘city 1′,’street 1’,false}, {‘city 2′,’street 2’,true}, {‘city 3′,’street 3’,false} ] 我希望输出为 [ { city:’city […]

JAVA中的Excel到Json转换器

我试图将excel数据转换为JSON格式。 我成功通过读取行​​和列来转换Excel数据并将数据设置为列表,然后将该List转换为JSON格式。 但是,我坚持下一级JSON,格式就像 这是我使用的代码,但尚未开始如何使像3列数据这样的嵌套数据应该像上面的图像一样放在一个数组中。 Pojo类 : public class Products implements Serializable{ @Id @Column(name=”ID”) private String id; @Column(name=”PRODUCTID”) private String productId; @Column(name=”NAMEID”) private String nameId; @Column(name=”NAME”) private String name; @Column(name=”P_DESC”) private String desc; @Column(name=”DIMENSION”) private String dimension; @Column(name=”CATEGORY”) private String category; @Column(name=”SUB_CATEGORY”) private String subcategory; @Column(name=”CATEGORYID”) private String categoryId; @Column(name=”SUBCATEGORYID”) private String subcategoryId; @Column(name=”TAGS”) private String […]