示例#1
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);
  }
示例#2
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);
    }
  }