use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project jsonschema2pojo by joelittlejohn.
the class SchemaGenerator method simpleTypeSchema.
private ObjectNode simpleTypeSchema(JsonNode exampleValue) {
try {
Object valueAsJavaType = this.objectMapper.treeToValue(exampleValue, Object.class);
SerializerProvider serializerProvider = new DefaultSerializerProvider.Impl().createInstance(this.objectMapper.getSerializationConfig(), BeanSerializerFactory.instance);
if (valueAsJavaType == null) {
SchemaAware valueSerializer = NullSerializer.instance;
return (ObjectNode) valueSerializer.getSchema(serializerProvider, null);
} else if (valueAsJavaType instanceof Long) {
// longs are 'integers' in schema terms
SchemaAware valueSerializer = (SchemaAware) serializerProvider.findValueSerializer(Integer.class, null);
ObjectNode schema = (ObjectNode) valueSerializer.getSchema(serializerProvider, null);
schema.put("minimum", Long.MAX_VALUE);
return schema;
} else {
Class<? extends Object> javaTypeForValue = valueAsJavaType.getClass();
SchemaAware valueSerializer = (SchemaAware) serializerProvider.findValueSerializer(javaTypeForValue, null);
return (ObjectNode) valueSerializer.getSchema(serializerProvider, null);
}
} catch (JsonProcessingException e) {
throw new GenerationException("Unable to generate a schema for this json example: " + exampleValue, e);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project dhis2-core by dhis2.
the class CustomLastUpdatedUserSerializerTest method serializeXml.
@Test
void serializeXml() throws Exception {
Writer jsonWriter = new StringWriter();
ToXmlGenerator jsonGenerator = new XmlFactory().createGenerator(jsonWriter);
SerializerProvider serializerProvider = new ObjectMapper().getSerializerProvider();
jsonGenerator.setNextName(new QName("urn:test", "lastUpdatedBy"));
new CustomLastUpdatedUserSerializer().serialize(user, jsonGenerator, serializerProvider);
jsonGenerator.flush();
assertEquals("<wstxns1:lastUpdatedBy xmlns:wstxns1=\"urn:test\" id=\"jshfdkd323\" name=\"Peter Brown\"/>", jsonWriter.toString());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project sts4 by spring-projects.
the class JSON method pathAsJson.
private static SimpleModule pathAsJson() {
SimpleModule m = new SimpleModule();
m.addSerializer(Path.class, new JsonSerializer<Path>() {
@Override
public void serialize(Path path, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
gen.writeString(path.toString());
}
});
m.addDeserializer(Path.class, new JsonDeserializer<Path>() {
@Override
public Path deserialize(JsonParser parse, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return Paths.get(parse.getText());
}
});
return m;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project cxf by apache.
the class JAXRSNonSpringJaxrsServletTest method testFeatureOnResourceClassUsingApplication.
@Test
public void testFeatureOnResourceClassUsingApplication() throws Exception {
final JsonSerializer<Object> defaultNullKeySerializer = Json.mapper().getSerializerProvider().getDefaultNullKeySerializer();
try {
// Swagger Core v3 does not interpret FormParam("") properly, sets property key as 'null' and fails the
// serialization with "Null key for a Map not allowed in JSON (use a converting NullKeySerializer?)"
Json.mapper().getSerializerProvider().setNullKeySerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeFieldName("");
}
});
String address = "http://localhost:" + PORT2 + "/bookstore/;JSESSIONID=xxx";
WebClient wc = WebClient.create(address);
Book book = wc.get(Book.class);
assertEquals(124L, book.getId());
assertEquals("root", book.getName());
// Check OpenAPI feature is working correctly
wc = WebClient.create("http://localhost:" + PORT2 + "/openapi.json");
Response openAPIResponse = wc.get();
assertEquals(200, openAPIResponse.getStatus());
} finally {
if (defaultNullKeySerializer != null) {
Json.mapper().getSerializerProvider().setNullKeySerializer(defaultNullKeySerializer);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project torodb by torodb.
the class DescriptionFactoryWrapper method expectAnyFormat.
@Override
public JsonAnyFormatVisitor expectAnyFormat(JavaType type) throws JsonMappingException {
SerializerProvider p = getProvider();
JsonSerializer<Object> s = p.findValueSerializer(type);
s.acceptJsonFormatVisitor(new DescriptionFactoryWrapper(this, getJsonPointer(), p), type);
return super.expectAnyFormat(type);
}
Aggregations