- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
具有以下json片段:
"Location": {
"Address": ""
},
public class Address implements Serializable
{
@JsonProperty("City")
private String city;
@JsonProperty("StateProvinceCode")
private String stateProvinceCode;
@JsonProperty("PostalCode")
private String postalCode;
@JsonProperty("CountryCode")
private String countryCode;
private final static long serialVersionUID = -4475717488164417476L;
/**
* No args constructor for use in serialization
*
*/
public Address() {
}
/**
*
* @param city
* @param countryCode
* @param postalCode
* @param stateProvinceCode
*/
public Address(String city, String stateProvinceCode, String postalCode, String countryCode) {
super();
this.city = city;
this.stateProvinceCode = stateProvinceCode;
this.postalCode = postalCode;
this.countryCode = countryCode;
}
getters and settes ...
com.xxx.Address
实例(尽管至少存在一个Creator):在[来源:UNKNOWN中,没有从字符串值('')\ n反序列化的String参数构造函数/工厂方法;行:-1,列:-1]
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}
最佳答案
根据@Dmitry Zagorulkin的建议,将DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT
转换为true
。有关更多详细信息,请检查docs。
这是我尝试复制该问题并通过添加注释突出显示的行来解决的代码。
public class JacksonExample2 {
private static String json1 = "{\r\n" +
" \"Location\": {\r\n" +
" \"Address\": \"\"\r\n" +
" }\r\n" +
"}";
public static void main(String[] args) throws JSONException, IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
// Add this line
mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
ParentData parentData = mapper.readValue(json1, ParentData.class);
Address address = new Address("New York", null, null, null);
LocationData locationData = new LocationData(address);
System.out.println(parentData);
}
}
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
class ParentData {
@JsonProperty("Location")
private LocationData locationData;
}
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
class LocationData {
@JsonProperty("Address")
private Address address;
}
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
class Address implements Serializable {
@JsonProperty("City")
private String city;
@JsonProperty("StateProvinceCode")
private String stateProvinceCode;
@JsonProperty("PostalCode")
private String postalCode;
@JsonProperty("CountryCode")
private String countryCode;
private final static long serialVersionUID = -4475717488164417476L;
}
关于java - 带有空白字符串的Jackson com.fasterxml.jackson.databind.exc.MismatchedInputException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60844488/
我正在尝试将包从“com.fasterxml.jackson”重新定位到我自己的包(即“mypackage.com.fasterxml.jackson”),然后在我拥有的另一个 JAR 中使用它。 我
我将 jackson 库从 2.5.4 升级到 2.10.1,如下所示,我收到以下错误: "WFLYCTL0080: Failed services" => { "jboss.depl
我在 Wildfly 8.2.1 和 Glassfish 4.1 中使用 Spring Data JPA 部署 Spring MVC 应用程序时遇到问题(它在 Wildfly 10 中工作,但我不允许
问题如何指示ObjectMapper他应该通过某些条件(字段)过滤对象的嵌套集合。通过代码查看解释: 通过代码进行解释: 我必须将 Container 对象转换为 JSON。但我想根据 Entry.v
我有一个如下的dto public class MyClass { @JsonProperty("value") @JsonInclude(JsonInclude.Include.NO
有没有办法反序列化 JSON 数组 {["a", "b", 1]} 进入以下 Java 类 class MyObject { private String firstItem; private
How does Jackson deserialisation work when creating a Java object from JSON? A common conception is
我从代码中得到以下输出:{“列表”:[{“x”:“y”},{“a”:“b”}]} 相反,我想得到输出[{"x":"y"},{"a":"b"}] 代码如下。 public class Test { Li
我需要生成确认此 XSD 的 XML: 所以输出是这样的: A B C 问题是,如果我像这样在 Java bean 中注释变量: @JsonProperty("Line"
我有来自客户的 xml: 和简单的 Java 类 import com.fasterxml.jackson.dataformat.xml.annotation.Jackso
我已映射实体,并以 JSON 格式发送到服务。这是我的实体 @Entity @Table(name = "company") @JsonIdentityInfo(generator = ObjectI
以下类(class)显示问题 - 无法解决导入 com.fasterxml.jackson - import com.fasterxml.jackson.annotation.JsonIgnorePr
我的字符串是:json = {"foo":"bar"}{"foo":"bar"} ======================== ObjectMapper mapper = new ObjectMa
我有以下 JSON: "segmentid": { "mot": { "@displaytype": "B", "@type": "BLT",
我有这样的 csv 文件: headerA;headerB;headerC val1;val2;val3; val4;val5;val6; some_word;val7; 所以。最后一行不同。它不适合
我有以下 XML 架构: Intermediate A Intro to A Advanced B 我需要将其转换为 POJO 为: public class Schedu
我正在使用两个 JSON。 第一个具有字符串形式的 ID。 "details": { "id": "316.0" } 另一个的 ID 为 Integer。 "details": { "
当尝试序列化一个类别时,我得到一个 stackoverflow。 异常 Warning: StandardWrapperValve[dispatcher]: Servlet.service() for
在 maven pom.xml 中: com.fasterxml.jackson.core jackson-core 2.5.0
本文整理了Java中com.fasterxml.jackson.core.json.WriterBasedJsonGenerator类的一些代码示例,展示了WriterBasedJsonGenerat
我是一名优秀的程序员,十分优秀!