【发布时间】:2016-08-03 22:43:43
【问题描述】:
我环顾四周,不认为这是其中任何一个的重复:
using Jackson annotations in Wildfly
jackson annotations being ignored
Wildfly and Jackson @JsonIgnore annotation
使用 Wildfly 10 并使用以下类部署战争:
@Provider
public class JaxApplication implements ContextResolver<ObjectMapper> {
private final ObjectMapper mapper;
public JaxApplication() {
mapper = new ObjectMapper();
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
//throw new RuntimeException("HERE");
}
@Override
public ObjectMapper getContext(Class<?> type) {
throw new RuntimeException("HERE");
//return mapper;
}
}
如果没有注释,我会在部署时看到构造函数中抛出的异常,但是当我向我的 REST 服务发出请求时,我看不到来自 getContext 方法的异常。
我在一个实体上有一个 @JsonIgnore 注释,但它不起作用,我正在使用的 @JsonIdentityInfo 注释也不起作用
该类看起来像这样(包括导入,以验证我使用的是 com.fasterxml.*)
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* Created by mb995a on 7/29/2016.
*/
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@request_id", scope=Request.class)
public class Request extends BaseEntity {
我需要在我的 REST 配置中做一些特别的事情吗?
@ApplicationPath("api")
public class RestApplication extends Application {
public RestApplication() {
super();
}
}
有什么想法吗?
编辑说:我还有一个使用 ObjectMapper 的单元测试,它可以正确序列化。
【问题讨论】:
标签: java json annotations