ClientConfig clientConfig = new DefaultClientConfig(); // Allow Jersey Client support JSON. clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); // Create your own Jackson ObjectMapper. ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); // Create your own JacksonJaxbJsonProvider and then assign it to the config. JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider(); jacksonProvider.setMapper(mapper); clientConfig.getSingletons().add(jacksonProvider); Client client = Client.create(clientConfig);
2013年3月13日 星期三
Jersey Client with Customize JSON (Jackson) Configuration
訂閱:
張貼留言 (Atom)
Here is an updated version for JAX-RS 2.0
回覆刪除ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
jacksonProvider.setMapper(objectMapper);
Client restClient = ClientBuilder.newClient(new ClientConfig(jacksonProvider));