List of usage examples for com.fasterxml.jackson.databind ObjectMapper getSerializationConfig
public SerializationConfig getSerializationConfig()
From source file:com.pressassociation.pr.filter.json.jackson.JacksonFiltersTest.java
@Test @Parameters(method = "methods") public void testFilterAllOutput(OverloadedFilterAllOutput method) { ObjectMapper mapper = method.filterAllOutput(new ObjectMapper(), "foo/bar"); AnnotationIntrospector introspector = mapper.getSerializationConfig().getAnnotationIntrospector(); Object filterId = introspector.findFilterId((Annotated) AnnotatedClass.construct(TestObject.class, introspector, mapper.getDeserializationConfig())); assertNotNull(filterId);/* w w w . j av a2s.c o m*/ PropertyFilter propertyFilter = mapper.getSerializationConfig().getFilterProvider() .findPropertyFilter(filterId, new TestObject()); assertNotNull(propertyFilter); assertTrue(propertyFilter instanceof JacksonMatcherFilter); assertEquals(Matcher.of("foo/bar"), ((JacksonMatcherFilter) propertyFilter).getMatcher()); }
From source file:org.usrz.libs.riak.introspection.RiakIntrospector.java
public RiakIntrospector() { final ObjectMapper mapper = new ObjectMapper(); typeFactory = mapper.getTypeFactory(); serializationConfig = mapper.getSerializationConfig().with(introspector); deserializationConfig = mapper.getDeserializationConfig().with(introspector); System.err.println(typeFactory.constructArrayType(String.class)); System.err.println(typeFactory.constructType(int.class).containedTypeCount()); System.err.println(typeFactory.constructType(Integer.class).containedTypeCount()); System.err.println(new ListConverter<String, Key>(null, new StringKeyConverter(null)) .getInputType(typeFactory).containedTypeCount()); System.err.println(//from ww w . j a v a 2 s .c om new ListConverter<String, Key>(null, new StringKeyConverter(null)).getOutputType(typeFactory)); }
From source file:com.pressassociation.pr.filter.json.jackson.JacksonRequestParamFilterTest.java
private void assertConfiguredWithMatcher(ObjectMapper mapper, Matcher matcher) { AnnotationIntrospector introspector = mapper.getSerializationConfig().getAnnotationIntrospector(); Object filterId = introspector.findFilterId((Annotated) AnnotatedClass.construct(TestObject.class, introspector, mapper.getDeserializationConfig())); assertNotNull(filterId);// w w w .j a va 2 s.c o m PropertyFilter propertyFilter = mapper.getSerializationConfig().getFilterProvider() .findPropertyFilter(filterId, new TestObject()); assertNotNull(propertyFilter); assertTrue(propertyFilter instanceof JacksonMatcherFilter); assertEquals(matcher, ((JacksonMatcherFilter) propertyFilter).getMatcher()); }
From source file:capital.scalable.restdocs.payload.JacksonRequestFieldSnippetTest.java
@Test public void noRequestBody() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); HandlerMethod handlerMethod = new HandlerMethod(new TestResource(), "addItem2"); this.snippet.expectRequestFields().withContents(equalTo("No request body.")); new JacksonRequestFieldSnippet() .document(operationBuilder.attribute(HandlerMethod.class.getName(), handlerMethod) .attribute(ObjectMapper.class.getName(), mapper).request("http://localhost").build()); }
From source file:capital.scalable.restdocs.payload.JacksonRequestFieldSnippetTest.java
@Test public void listRequest() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); HandlerMethod handlerMethod = new HandlerMethod(new TestResource(), "addItems", List.class); JavadocReader javadocReader = mock(JavadocReader.class); when(javadocReader.resolveFieldComment(Item.class, "field1")).thenReturn("A string"); when(javadocReader.resolveFieldComment(Item.class, "field2")).thenReturn("An integer"); this.snippet.expectRequestFields() .withContents(tableWithHeader("Path", "Type", "Optional", "Description") .row("[].field1", "String", "true", "A string.") .row("[].field2", "Integer", "true", "An integer.")); new JacksonRequestFieldSnippet() .document(operationBuilder.attribute(HandlerMethod.class.getName(), handlerMethod) .attribute(ObjectMapper.class.getName(), mapper) .attribute(JavadocReader.class.getName(), javadocReader) .attribute(ConstraintReader.class.getName(), mock(ConstraintReader.class)) .request("http://localhost").content("{\"field1\":\"test\"}").build()); }
From source file:capital.scalable.restdocs.payload.JacksonRequestFieldSnippetTest.java
@Test public void jsonSubTypesRequest() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); HandlerMethod handlerMethod = new HandlerMethod(new TestResource(), "addSubItem", ParentItem.class); JavadocReader javadocReader = mock(JavadocReader.class); when(javadocReader.resolveFieldComment(ParentItem.class, "type")).thenReturn("A type"); when(javadocReader.resolveFieldComment(ParentItem.class, "commonField")).thenReturn("A common field"); when(javadocReader.resolveFieldComment(SubItem1.class, "subItem1Field")).thenReturn("A sub item 1 field"); when(javadocReader.resolveFieldComment(SubItem2.class, "subItem2Field")).thenReturn("A sub item 2 field"); ConstraintReader constraintReader = mock(ConstraintReader.class); this.snippet.expectRequestFields().withContents(tableWithHeader("Path", "Type", "Optional", "Description") .row("type", "String", "true", "A type.").row("commonField", "String", "true", "A common field.") .row("subItem1Field", "Boolean", "true", "A sub item 1 field.") .row("subItem2Field", "Integer", "true", "A sub item 2 field.")); new JacksonRequestFieldSnippet() .document(operationBuilder.attribute(HandlerMethod.class.getName(), handlerMethod) .attribute(ObjectMapper.class.getName(), mapper) .attribute(JavadocReader.class.getName(), javadocReader) .attribute(ConstraintReader.class.getName(), constraintReader).request("http://localhost") .content("{\"type\":\"1\"}").build()); }
From source file:com.github.camellabs.iot.cloudlet.document.sdk.RestDocumentService.java
@Override public T findOne(Class<T> documentClass, String id) { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); try {//ww w . j av a 2s . co m String response = restClient.getForObject( format("%s/findOne/%s/%s", baseUrl, pojoClassToCollection(documentClass), id), String.class); return mapper.readValue(response, documentClass); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:capital.scalable.restdocs.payload.JacksonRequestFieldSnippetTest.java
@Test public void simpleRequest() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); HandlerMethod handlerMethod = new HandlerMethod(new TestResource(), "addItem", Item.class); JavadocReader javadocReader = mock(JavadocReader.class); when(javadocReader.resolveFieldComment(Item.class, "field1")).thenReturn("A string"); when(javadocReader.resolveFieldComment(Item.class, "field2")) .thenReturn("An integer<br>\n Very important\n <p>\n field"); ConstraintReader constraintReader = mock(ConstraintReader.class); when(constraintReader.isMandatory(NotBlank.class)).thenReturn(true); when(constraintReader.getOptionalMessages(Item.class, "field1")).thenReturn(singletonList("false")); when(constraintReader.getConstraintMessages(Item.class, "field2")) .thenReturn(singletonList("A constraint")); this.snippet.expectRequestFields() .withContents(tableWithHeader("Path", "Type", "Optional", "Description") .row("field1", "String", "false", "A string.") .row("field2", "Integer", "true", "An integer" + lineBreak() + "Very important" + lineBreak() + lineBreak() + "field." + lineBreak() + "A constraint.")); new JacksonRequestFieldSnippet() .document(operationBuilder.attribute(HandlerMethod.class.getName(), handlerMethod) .attribute(ObjectMapper.class.getName(), mapper) .attribute(JavadocReader.class.getName(), javadocReader) .attribute(ConstraintReader.class.getName(), constraintReader).request("http://localhost") .content("{\"field1\":\"test\"}").build()); }
From source file:com.github.camellabs.iot.cloudlet.document.sdk.RestDocumentService.java
@Override public List<T> findMany(Class<T> documentClass, String... ids) { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); try {//from w ww .ja v a 2s. com String response = restClient.postForObject( format("%s/findMany/%s", baseUrl, pojoClassToCollection(documentClass)), new Ids(ids), String.class); T[] arrayResponse = mapper.readValue(response, classOfArrayOfClass(documentClass)); return ImmutableList.copyOf(arrayResponse); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.redisson.codec.JsonJacksonCodec.java
private void createObjectMapper(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true); objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); }