Ejemplo n.º 1
0
  static {
    // Create a custom Mongo BSON mapper
    MONGO_MAPPER = new ObjectMapper();
    TweakedMongoJackModule.configure(MONGO_MAPPER);

    // Don't include null props or empty lists
    MONGO_MAPPER.setSerializationInclusion(Include.NON_EMPTY);

    // Only include whitelisted props
    MONGO_MAPPER.setVisibilityChecker(
        MONGO_MAPPER
            .getSerializationConfig()
            .getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.NONE)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));

    JSON_MAPPER = new ObjectMapper();
    JSON_MAPPER.setSerializationInclusion(Include.NON_EMPTY);
    JSON_MAPPER.setVisibilityChecker(
        JSON_MAPPER
            .getSerializationConfig()
            .getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.NONE)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    JSON_MAPPER.registerModule(new JsonModule());
  }
Ejemplo n.º 2
0
  static {
    // Allow any visibility
    mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));
    rootMapper.setVisibilityChecker(
        rootMapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));

    // Add serializers
    SimpleModule module = new SimpleModule("SerialiationModule");
    module.addSerializer(new DateTimeSerializer());
    mapper.registerModule(module);
    rootMapper.registerModule(module);

    // Allow empty beans
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    rootMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    // Allow root keys
    rootMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
    rootMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

    // Allow single quotes
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    rootMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

    // Allow unknown properties
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    rootMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  }
Ejemplo n.º 3
0
 {
   mapper.setVisibilityChecker(
       mapper
           .getSerializationConfig()
           .getDefaultVisibilityChecker()
           .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
           .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
           .withSetterVisibility(JsonAutoDetect.Visibility.NONE));
 }
Ejemplo n.º 4
0
  static {
    final SimpleModule module =
        new SimpleModule("SwfModule", new Version(1, 0, 0, null, null, null))
            .addSerializer(Date.class, new EpochSecondsDateSerializer())
            .addDeserializer(Date.class, new EpochSecondsDateDeserializer());
    mapper.registerModule(module);
    mapper.setDateFormat(new EpochSecondsDateFormat());
    mapper.addMixInAnnotations(SimpleWorkflowMessage.class, BindingMixIn.class);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
    mapper.setVisibilityChecker(
        new VisibilityChecker.Std(VisibilityChecker.Std.class.getAnnotation(JsonAutoDetect.class)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean isSetterVisible(final Method m) {
            return !(m.getParameterCount() == 1 && m.getParameterTypes()[0].isEnum())
                && super.isSetterVisible(m);
          }
        });
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  }
  @Before
  public void setUp() {
    SimpleModule module = new SimpleModule();
    module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
    module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(module);
    mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    mapper.setVisibilityChecker(
        mapper
            .getSerializationConfig()
            .getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY));

    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(server.url("/"))
            .addConverterFactory(JacksonConverterFactory.create(mapper))
            .build();
    service = retrofit.create(Service.class);
  }
Ejemplo n.º 6
0
  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);
    }
  }