Jboss Jackson marshal/unmarshal在jaxrs wildfly 15中表现不同
首先,我们正在将应用程序从JBoss 7迁移到Wildfly 15,这是我们将FasterXML(2.9.5)、RestEasy(3.6.2.final)的所有依赖项更新到Wildfly 15模块支持的版本的一部分。 我们还更新了代码库,使用fasterxml代替codehaus。现在,编译和部署已经成功。当我们通过postman触发REST请求时,某些参数无法反序列化。示例如下Jboss Jackson marshal/unmarshal在jaxrs wildfly 15中表现不同,jboss,jackson,jax-rs,wildfly,resteasy,Jboss,Jackson,Jax Rs,Wildfly,Resteasy,首先,我们正在将应用程序从JBoss 7迁移到Wildfly 15,这是我们将FasterXML(2.9.5)、RestEasy(3.6.2.final)的所有依赖项更新到Wildfly 15模块支持的版本的一部分。 我们还更新了代码库,使用fasterxml代替codehaus。现在,编译和部署已经成功。当我们通过postman触发REST请求时,某些参数无法反序列化。示例如下 @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = &quo
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "User", propOrder = {
"userInfo",
"profiles",
"groups"
})
public class User extends NfvdResource implements IUser {
@XmlElement(name = "user-info", required = true)
protected UserInfo userInfo;
protected Profiles profiles;
protected Groups groups;
..
..
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Groups", propOrder = {
"group"
})
public class Groups implements IGroups {
private List<Group> group;
@Override
public List<Group> getGroup() {
if (group == null) {
group = new ArrayList<Group>();
}
return this.group;
}
@Override
public String toString() {
return "Groups [group=" + group + "]";
}
}
@XmlRootElement( name = "user")
public interface IUser extends IProfiles, IGroups {
@JsonProperty("user-info")
public UserInfo getUserInfo();
@JsonIgnore
public Profiles getProfiles();
@JsonIgnore
public Groups getGroups();
}
@XmlRootElement(name = "profiles")
public interface IProfiles {
@JsonProperty("profiles")
public List<Profile> getProfile();
}
public interface IGroups {
@JsonProperty("groups")
public List<Group> getGroup();
}
{
"user-info":{"username":"dem115","name":"dem115","surname":"dem115","phonenumber":"123546","email":"abc@xyz.com","preferred-language":"en-us","preferred-theme":"light","role":"domain","password":"xxxx","public-key":"TBD"
},
"profiles":[
{"type":"domain","name":"administrator","description":"","operations":[]},
{"type":"domain","name":"scriptManager","description":"","operations":[]}
],
"groups":[
{"domain":"sample.domain","datacenter":null,"organization":null,"tenant":null,"vnf":null,"type":"domain","@uri":"/abc/domains/95b3c440-843e-4163-b737-cc0f273238c1","@internal-id":"xxxxxx-843e-4163-b737-cc0f273238c1"}
],
}
在上述有效负载下,用户
对象中的配置文件
和组
参数被设置为null,JBoss 7和jackson1以及相关配置的情况并非如此。
作为迁移的一部分,我们是否缺少一些配置是我们不确定的
为了让它发挥作用,我们提出了以下解决方法。只需在profiles
和groups
上添加@jsonunrapped注释,字段编组和解编就可以了
@JsonUnwrapped
protected Profiles profiles;
@JsonUnwrapped
protected Groups groups;
我们不确定我们之前工作的迁移中缺少了什么。我们也不确定这个注释的副作用。
这里的另一个问题是,我们在应用程序中有类似的模式(大约250个java文件)。所以我们担心这会影响功能
从根本上说,我们缺少什么?有人能帮我照一下吗?在经过一周多的调查之后,我们将到达这个论坛
另一个需要提及的重要问题是,我们也正在将java 1.7迁移到jdk11,作为这个过程的一部分。
提前感谢您的帮助。这可以自定义Jackson在json中序列化bean的方式。 例如,在CDI集装箱中(如Wildfly): 查看并非您发布的所有功能。
@Provider
@Produces({MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON})
public class CustomizedJsonProvider extends JacksonJsonProvider {
public CustomizedJsonProvider() {
super();
super.setMapper( initMapper() );
}
private static ObjectMapper initMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}
}