/** * Creates a {@link JsonMediaTypeCodec} for the view class (specified as the JsonView annotation value). * @param viewClass The view class * @return The codec */ @Override public @Nonnull JsonMediaTypeCodec resolveJsonViewCodec(@Nonnull Class<?> viewClass) { ArgumentUtils.requireNonNull("viewClass", viewClass); JsonMediaTypeCodec codec = jsonViewCodecs.get(viewClass); if (codec == null) { ObjectMapper viewMapper = objectMapper.copy(); viewMapper.setConfig(viewMapper.getSerializationConfig().withView(viewClass)); codec = new JsonMediaTypeCodec(viewMapper, applicationConfiguration, codecConfiguration); jsonViewCodecs.put(viewClass, codec); } return codec; } }
objectMapper.registerModule(new SanitizerModule()); objectMapper.registerModule(new JSR353Module()); objectMapper.setConfig( objectMapper.getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); if (Context.getConfig().getBoolean("mapper.prettyPrintedJson")) {
@Autowired public HttpTemplateSchemeLoader(ObjectMapper pipelineTemplateObjectMapper) { this.jsonObjectMapper = pipelineTemplateObjectMapper; this.yamlObjectMapper = new ObjectMapper(new YAMLFactory()) .setConfig(jsonObjectMapper.getSerializationConfig()) .setConfig(jsonObjectMapper.getDeserializationConfig()); this.okHttpClient = new OkHttpClient(); }
public ResourceSchemeLoader(String rootPath, ObjectMapper objectMapper) { this.rootPath = rootPath; this.jsonObjectMapper = objectMapper; this.yamlObjectMapper = new ObjectMapper(new YAMLFactory()) .setConfig(jsonObjectMapper.getSerializationConfig()) .setConfig(jsonObjectMapper.getDeserializationConfig()); }
@Autowired public FileTemplateSchemeLoader(ObjectMapper pipelineTemplateObjectMapper) { this.jsonObjectMapper = pipelineTemplateObjectMapper; this.yamlObjectMapper = new ObjectMapper(new YAMLFactory()) .setConfig(jsonObjectMapper.getSerializationConfig()) .setConfig(jsonObjectMapper.getDeserializationConfig()); }
public class VerboseMinimalSerializer extends JsonSerializer<Object> { @Override public void serialize(Object object, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); mapper.setSerializationInclusion(Include.NON_NULL); mapper.setConfig(mapper.getSerializationConfig().withView(VerboseViewB.Minimal.class)); jsonGenerator.setCodec(mapper); jsonGenerator.writeObject(object); } }
private JSONCoercibleType() { // prevents json object from being created with duplicate names at the same level mapper.setConfig( mapper.getDeserializationConfig() .with( DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY ) ); }
@Override protected void configure() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); objectMapper.registerModule(new KotlinModule()); SerializationConfig config = objectMapper.getSerializationConfig() .withoutFeatures(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setConfig(config); bind(ObjectReader.class).annotatedWith(Ipc.class).toInstance(objectMapper.reader()); bind(ObjectWriter.class).annotatedWith(Ipc.class).toInstance(objectMapper.writer()); // have to have ObjectMapper for Jersey integration bind(ObjectMapper.class).annotatedWith(Ipc.class).toInstance(objectMapper); } }
public class JacksonView1 { public static class publicView{} public static class User { public User(Long id, String showName, List<String> callableQueues) { this.id = id; this.showName = showName; this.callableQueues = callableQueues; } @JsonView(publicView.class) public final Long id; public final String showName; @JsonView(publicView.class) public final List<String> callableQueues; } public static void main(String[] args) { User user = new User(123l, "name", Arrays.asList("a", "b")); ObjectMapper mapper = new ObjectMapper(); mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION); mapper.setConfig(mapper.getSerializationConfig() .withView(publicView.class)); System.out.println(mapper.convertValue(user, JsonNode.class)); } }
@Inject public DefaultWebHookManager(ObjectMapper mapper, ExecutorService executor) { this.mapper = mapper.copy(); this.mapper.setConfig(this.mapper.getSerializationConfig().withView(RestView.class)); this.executor = executor; }
ObjectMapper mapper1 = new ObjectMapper(); mapper1.setConfig(mapper1.getDeserializationConfig().withRootName("data")); TargetCountry[] result1 = mapper1.readValue(JSON, TargetCountry[].class); System.out.println("Option 1: " + Arrays.toString(result1));
@Inject public JacksonContextResolver(ObjectMapper objectMapper) { this.objectMapper = objectMapper.copy(); this.objectMapper.setConfig(this.objectMapper.getSerializationConfig().withView(RestView.class)); }
public static ObjectMapper patchMapper() { if (patchMapper == null) { patchMapper = new ObjectMapper(); patchMapper.addMixInAnnotations(ObjectMeta.class, ObjectMetaMixIn.class); patchMapper.addMixInAnnotations(Build.class, BuildMixIn.class); patchMapper.setConfig(patchMapper().getSerializationConfig().without(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)); } return patchMapper; }
private JsonNode extractResult(String jsonString) throws IOException { ObjectMapper om = new ObjectMapper(); om.setConfig(om.getDeserializationConfig().with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)); try { final JsonNode result = om.readValue(jsonString, ObjectNode.class).get("results"); if (result == null) { throw new IllegalArgumentException("No field 'results' in " + jsonString); } return result; } catch (JsonMappingException e) { LOGGER.warn("error mapping response '{}' to json", jsonString, e); return om.createArrayNode(); } }
each.configure(mapper); mapper.setConfig(mapper.getSerializationConfig().withView(DefaultView.class));
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); AnnotationIntrospector introspectorPair = AnnotationIntrospector.pair(primary, secondary); objectMapper.setConfig( objectMapper.getSerializationConfig() .with(introspectorPair) .with(SerializationFeature.INDENT_OUTPUT)); deserializeObjectMapper.setConfig(objectMapper.getDeserializationConfig() .with(introspectorPair) .with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) customSerializationMapper.setConfig(customSerializationMapper.getDeserializationConfig().with(introspectorPair)); customSerializationMapper.setConfig(customSerializationMapper.getSerializationConfig().with(introspectorPair).with(SerializationFeature.INDENT_OUTPUT)); customObjectMapper.setDefaultTyping(typer); customObjectMapper.setConfig(customObjectMapper.getSerializationConfig().with(introspectorPair).with(SerializationFeature.INDENT_OUTPUT)); deserializeObjectMapper.setConfig(deserializeObjectMapper.getDeserializationConfig().with(introspectorPair));