import java.io.File; import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility; import org.codehaus.jackson.map.ObjectMapper; public class JacksonFoo { public static void main(String[] args) throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker( mapper.getVisibilityChecker() .withFieldVisibility(Visibility.ANY)); Thing thing = mapper.readValue(new File("input.json"), Thing.class); System.out.println(mapper.writeValueAsString(thing)); } }
/** * Constructor. */ // Use deprecated method to ensure we don't break with older versions of jackson @SuppressWarnings("deprecation") public Serializer() { mapper .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setVisibilityChecker( mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE)); }
/** * Constructor. */ // Use deprecated method to ensure we don't break with older versions of jackson @SuppressWarnings("deprecation") public Serializer() { mapper .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setVisibilityChecker( mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE)); }
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));
public void init() { LOG.log(Level.INFO, "Creating JsonSchemaLookup instance"); try { if (mapper == null) { mapper = new ObjectMapper(); mapper.setVisibility(new IgnorePropertiesBackedByTransientFields(mapper.getVisibilityChecker())); JaxbAnnotationModule module1 = new JaxbAnnotationModule(); mapper.registerModule(module1); BeanValidationAnnotationModule module2 = new BeanValidationAnnotationModule(); mapper.registerModule(module2); } // now lets expose the mbean... singleton = this; } catch (Exception e) { LOG.log(Level.WARNING, "Exception during initialization: ", e); throw new RuntimeException(e); } }
public void init() { LOG.log(Level.INFO, "Creating JsonSchemaLookup instance"); try { if (mapper == null) { mapper = new ObjectMapper(); mapper.setVisibilityChecker(new IgnorePropertiesBackedByTransientFields(mapper.getVisibilityChecker())); JaxbAnnotationModule module1 = new JaxbAnnotationModule(); mapper.registerModule(module1); BeanValidationAnnotationModule module2 = new BeanValidationAnnotationModule(); mapper.registerModule(module2); } // now lets expose the mbean... singleton = this; } catch (Exception e) { LOG.log(Level.WARNING, "Exception during initialization: ", e); throw new RuntimeException(e); } }
public void init() { LOG.debug("Creating hawtio SchemaLookup instance"); try { if (mapper == null) { mapper = new ObjectMapper(); mapper.setVisibilityChecker(new IgnorePropertiesBackedByTransientFields(mapper.getVisibilityChecker())); JaxbAnnotationModule module1 = new JaxbAnnotationModule(); mapper.registerModule(module1); BeanValidationAnnotationModule module2 = new BeanValidationAnnotationModule(); mapper.registerModule(module2); } // now lets expose the mbean... super.init(); singleton = this; } catch (Exception e) { LOG.warn("Exception during initialization: ", e); throw new RuntimeException(e); } }
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); System.out.println(mapper.writeValueAsString(new Placement()));
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); System.out.println(mapper.writeValueAsString(new Placement()));
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); System.out.println(mapper.writeValueAsString(new Placement()));
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); System.out.println(mapper.writeValueAsString(new Placement()));
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY)); mapper.getSerializationConfig().addMixInAnnotations(Placement.class, SkipFileDataMixIn.class); System.out.println(mapper.writeValueAsString(new Placement()));
@SuppressWarnings("deprecation") private JsonNode serialiseThreadStateToJson(List<ThreadState> threadStates) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setVisibilityChecker(mapper.getVisibilityChecker() .with(JsonAutoDetect.Visibility.NONE)); String json = mapper.writeValueAsString(threadStates); return mapper.readTree(json); }
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));