我已经看过在这里,不认为这是任何这些重复:Wildfly无视杰克逊的注解,而不是使用@Provider类
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的单元测试,它正确序列化。