public JsonMapper(Include include) { mapper = new ObjectMapper(); // 设置输出时包含属性的风格 if (include != null) { mapper.setSerializationInclusion(include); } // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); }
public JsonMapper(Include include) { mapper = new ObjectMapper(); // 设置输出时包含属性的风格 if (include != null) { mapper.setSerializationInclusion(include); } // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); }
static ObjectMapper getDefaultObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); return mapper; }
ObjectMapper mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
public Console( final OutputFormat outputFormat, final KsqlTerminal terminal, final RowCaptor rowCaptor ) { this.outputFormat = Objects.requireNonNull(outputFormat, "outputFormat"); this.terminal = Objects.requireNonNull(terminal, "terminal"); this.rowCaptor = Objects.requireNonNull(rowCaptor, "rowCaptor"); this.cliSpecificCommands = Maps.newLinkedHashMap(); this.objectMapper = new ObjectMapper().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); }
public JacksonContext() { this.mapper = new ObjectMapper() .enable(SerializationFeature.INDENT_OUTPUT) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .setSerializationInclusion(JsonInclude.Include.NON_NULL); }
private static ObjectMapper newMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE); mapper.disable(SerializationFeature.CLOSE_CLOSEABLE); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); Reflections reflections = new Reflections("com.twitter.ambrose"); Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class); mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()])); return mapper; } }
@Inject public NodeInfoMapper() { this.mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); }
public static GenesisJson loadGenesisJson(InputStream genesisJsonIS) throws RuntimeException { String json = null; try { json = new String(ByteStreams.toByteArray(genesisJsonIS)); ObjectMapper mapper = new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); GenesisJson genesisJson = mapper.readValue(json, GenesisJson.class); return genesisJson; } catch (Exception e) { Utils.showErrorAndExit("Problem parsing genesis: "+ e.getMessage(), json); throw new RuntimeException(e.getMessage(), e); } }
/** * Creates a new minimal {@link ObjectMapper} that will work with Dropwizard out of box. * <p><b>NOTE:</b> Use it, if the default Dropwizard's {@link ObjectMapper}, created in * {@link #newObjectMapper()}, is too aggressive for you.</p> */ public static ObjectMapper newMinimalObjectMapper() { return new ObjectMapper() .registerModule(new GuavaModule()) .setSubtypeResolver(new DiscoverableSubtypeResolver()) .disable(FAIL_ON_UNKNOWN_PROPERTIES); }
public TimedJsonStreamParser(List<TblColRef> allColumns, Map<String, String> properties) { this.allColumns = allColumns; if (properties == null) { properties = StreamingParser.defaultProperties; } tsColName = properties.get(PROPERTY_TS_COLUMN_NAME); tsParser = properties.get(PROPERTY_TS_PARSER); separator = properties.get(PROPERTY_EMBEDDED_SEPARATOR); strictCheck = Boolean.parseBoolean(properties.get(PROPERTY_STRICT_CHECK)); if (!StringUtils.isEmpty(tsParser)) { try { Class clazz = Class.forName(tsParser); Constructor constructor = clazz.getConstructor(Map.class); streamTimeParser = (AbstractTimeParser) constructor.newInstance(properties); } catch (Exception e) { throw new IllegalStateException("Invalid StreamingConfig, tsParser " + tsParser + ", parserProperties " + properties + ".", e); } } else { throw new IllegalStateException("Invalid StreamingConfig, tsParser " + tsParser + ", parserProperties " + properties + "."); } mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); mapper.enable(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY); }
@BeforeClass public static void setUpClass() throws Exception { mapper = new ObjectMapper(); mapper.disable(MapperFeature.AUTO_DETECT_GETTERS); mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); mapper.disable(MapperFeature.AUTO_DETECT_FIELDS); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); jgen = mapper.getFactory().createGenerator(new StringWriter()); }
@BeforeClass public static void initClassStubData() { mapper = new ObjectMapper(); mapper.disable(MapperFeature.AUTO_DETECT_GETTERS); mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); mapper.disable(MapperFeature.AUTO_DETECT_FIELDS); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); treeMapSerializer = new TreeMapSerializer(); }
@BeforeClass public static void initClassStubData() { mapper = new ObjectMapper(); mapper.disable(MapperFeature.AUTO_DETECT_GETTERS); mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS); mapper.disable(MapperFeature.AUTO_DETECT_FIELDS); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); treeMapNodeSerializer = new TreeMapNodeSerializer(); }
protected void init(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setVisibility(objectMapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class); }
protected void init(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setVisibility(objectMapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class); }
private static ObjectMapper configure(ObjectMapper mapper) { mapper.registerModule(new GuavaModule()); mapper.registerModule(new GuavaExtrasModule()); mapper.registerModule(new CaffeineModule()); mapper.registerModule(new JodaModule()); mapper.registerModule(new AfterburnerModule()); mapper.registerModule(new FuzzyEnumModule()); mapper.registerModule(new ParameterNamesModule()); mapper.registerModule(new Jdk8Module()); mapper.registerModule(new JavaTimeModule()); mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy()); mapper.setSubtypeResolver(new DiscoverableSubtypeResolver()); mapper.disable(FAIL_ON_UNKNOWN_PROPERTIES); return mapper; } }
public static ObjectMapper createDefaultMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, true); mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); mapper.registerModule(CloseableIterableDeserializer.getModule()); // Allow unknown properties. This will help to avoid conflicts between Gaffer versions. mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, STRICT_JSON_DEFAULT); // Using the deprecated version for compatibility with older versions of jackson mapper.registerModule(new JSR310Module()); // Use the 'setFilters' method so it is compatible with older versions of jackson mapper.setFilters(getFilterProvider()); // Allow simple class names or full class names to be used in JSON. // We must set this to true to ensure serialisation into json uses the // full class name. Otherwise, json deserialisation may fail on worker nodes in Accumulo/HBase. SimpleClassNameCache.setUseFullNameForSerialisation(true); SimpleClassNameIdResolver.configureObjectMapper(mapper); return mapper; }
JacksonStandardJavaScriptSerializer(final String jacksonPrefix) { super(); this.mapper = new ObjectMapper(); this.mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); this.mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); this.mapper.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII); this.mapper.getFactory().setCharacterEscapes(new JacksonThymeleafCharacterEscapes()); this.mapper.setDateFormat(new JacksonThymeleafISO8601DateFormat()); /* * Now try to (conditionally) initialize support for Jackson serialization of JSR310 (java.time) objects, * by making use of the 'jackson-datatype-jsr310' optional dependency. */ final Class<?> javaTimeModuleClass = ClassLoaderUtils.findClass(jacksonPrefix + ".datatype.jsr310.JavaTimeModule"); if (javaTimeModuleClass != null) { // JSR310 support for Jackson is present in classpath try { this.mapper.registerModule((Module)javaTimeModuleClass.newInstance()); this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); } catch (final InstantiationException e) { throw new ConfigurationException("Exception while trying to initialize JSR310 support for Jackson", e); } catch (final IllegalAccessException e) { throw new ConfigurationException("Exception while trying to initialize JSR310 support for Jackson", e); } } }
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) .disable(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY) .setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy()) .setSubtypeResolver(subtypeResolver)