コード例 #1
0
ファイル: StreamResource.java プロジェクト: nesl/SensorSafe
 private String getStreamJsonPrefix(Stream stream) throws JsonProcessingException {
   ObjectMapper mapper = new ObjectMapper();
   AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
   mapper.setAnnotationIntrospector(introspector);
   JSONObject json = (JSONObject) JSONValue.parse(mapper.writeValueAsString(stream));
   String strJson = json.toString();
   return strJson.substring(0, strJson.length() - 1) + ",\"tuples\":[";
 }
コード例 #2
0
  /**
   * Add the route in the database if it's not already, or update its state.
   *
   * @param routes being added to the app
   */
  @Override
  public void onRoutesAdd(Collection<Route> routes) {
    for (Route routeCamel : routes) {
      // adding a performance counter on the route
      if (routeCamel instanceof EventDrivenConsumerRoute) {
        EventDrivenConsumerRoute edcr = (EventDrivenConsumerRoute) routeCamel;
        Processor processor = edcr.getProcessor();
        if (processor instanceof InstrumentationProcessor) {
          InstrumentationProcessor ip = (InstrumentationProcessor) processor;
          ConsolePerformanceCounter counter =
              new ConsolePerformanceCounter(routeCamel.getId(), repository);
          ip.setCounter(counter);
          log.debug("Adding a counter" + counter.toString() + " to " + routeCamel.getId());
        }
      }

      // saving route in database
      log.debug("Route added " + routeCamel.getId());
      com.ninja_squad.console.Route route = repository.findRoute(routeCamel.getId());
      if (route == null) {
        route =
            new com.ninja_squad.console.Route(routeCamel.getId())
                .state(State.Started)
                .uri(routeCamel.getEndpoint().getEndpointUri());
        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector introspector =
            new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
        // make serializer use JAXB annotations (only)
        mapper.setAnnotationIntrospector(introspector);
        String definition = null;
        RouteDefinition routeDefinition = routeCamel.getRouteContext().getRoute();
        try {
          definition = mapper.writeValueAsString(routeDefinition);
        } catch (IOException e) {
          log.error("Error while marshalling route definition", e);
        }
        route.setDefinition(definition);
        for (ProcessorDefinition<?> stepDefinition : routeDefinition.getOutputs()) {
          if (stepDefinition.getId() == null) {
            stepDefinition.setId(stepDefinition.getClass().getSimpleName());
          }
          route.getSteps().put(stepDefinition.getId(), stepDefinition.getLabel());
        }
        repository.save(route);
      }

      // saving state in database
      RouteState routeState = repository.lastRouteState(routeCamel.getId());
      if (routeState == null || routeState.getState().equals(State.Stopped)) {
        routeState = new RouteState();
        routeState.setRouteId(routeCamel.getId());
        routeState.setState(State.Started);
        routeState.setTimestamp(DateTime.now().getMillis());
        repository.save(routeState);
      }
    }
  }
コード例 #3
0
ファイル: AppConfig.java プロジェクト: dmgn/floatinvoice
 @Bean
 public ObjectMapper jacksonObjectMapper() {
   ObjectMapper om = new ObjectMapper();
   om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
   AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
   // JaxbAnnotationIntrospector jai = new JaxbAnnotationIntrospector(om.getTypeFactory());
   // AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
   om.setAnnotationIntrospector(primary);
   om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
   om.setSerializationInclusion(Include.NON_NULL);
   return om;
 }
コード例 #4
0
 private ObjectMapper getObjectMapper() throws IOException {
   if (JacksonJsonRopMarshaller.objectMapper == null) {
     ObjectMapper objectMapper = new ObjectMapper();
     AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
     objectMapper.setAnnotationIntrospector(introspector);
     objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
     objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
     objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
     // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
     JacksonJsonRopMarshaller.objectMapper = objectMapper;
   }
   return JacksonJsonRopMarshaller.objectMapper;
 }
コード例 #5
0
  private static ObjectMapper createMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    mapper.setDateFormat(dateFormat);
    mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
    mapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);

    addQueryMapper(mapper);
    return mapper;
  }
コード例 #6
0
  public void testAnnotationIntrospectorCopyin() {
    ObjectMapper m = new ObjectMapper();
    m.setAnnotationIntrospector(new MyAnnotationIntrospector());
    assertEquals(
        MyAnnotationIntrospector.class,
        m.getDeserializationConfig().getAnnotationIntrospector().getClass());
    ObjectMapper m2 = m.copy();

    assertEquals(
        MyAnnotationIntrospector.class,
        m2.getDeserializationConfig().getAnnotationIntrospector().getClass());
    assertEquals(
        MyAnnotationIntrospector.class,
        m2.getSerializationConfig().getAnnotationIntrospector().getClass());
  }
コード例 #7
0
 /** Returns a new JSON object mapper. */
 private ObjectMapper buildObjectMapper() {
   ObjectMapper result = new ObjectMapper();
   result.setAnnotationIntrospector(new JaxbAnnotationIntrospector(result.getTypeFactory()));
   result.enable(SerializationFeature.INDENT_OUTPUT);
   return result;
 }
コード例 #8
0
  /**
   * Configure an existing {@link ObjectMapper} instance with this builder's settings. This can be
   * applied to any number of {@code ObjectMappers}.
   *
   * @param objectMapper the ObjectMapper to configure
   */
  @SuppressWarnings("deprecation")
  public void configure(ObjectMapper objectMapper) {
    Assert.notNull(objectMapper, "ObjectMapper must not be null");

    if (this.findModulesViaServiceLoader) {
      // Jackson 2.2+
      objectMapper.registerModules(ObjectMapper.findModules(this.moduleClassLoader));
    } else if (this.findWellKnownModules) {
      registerWellKnownModulesIfAvailable(objectMapper);
    }

    if (this.modules != null) {
      for (Module module : this.modules) {
        // Using Jackson 2.0+ registerModule method, not Jackson 2.2+ registerModules
        objectMapper.registerModule(module);
      }
    }
    if (this.moduleClasses != null) {
      for (Class<? extends Module> module : this.moduleClasses) {
        objectMapper.registerModule(BeanUtils.instantiate(module));
      }
    }

    if (this.dateFormat != null) {
      objectMapper.setDateFormat(this.dateFormat);
    }
    if (this.locale != null) {
      objectMapper.setLocale(this.locale);
    }
    if (this.timeZone != null) {
      objectMapper.setTimeZone(this.timeZone);
    }

    if (this.annotationIntrospector != null) {
      objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
    }
    if (this.propertyNamingStrategy != null) {
      objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy);
    }
    if (this.serializationInclusion != null) {
      objectMapper.setSerializationInclusion(this.serializationInclusion);
    }

    if (this.filters != null) {
      // Deprecated as of Jackson 2.6, but just in favor of a fluent variant.
      objectMapper.setFilters(this.filters);
    }

    for (Class<?> target : this.mixIns.keySet()) {
      // Deprecated as of Jackson 2.5, but just in favor of a fluent variant.
      objectMapper.addMixInAnnotations(target, this.mixIns.get(target));
    }

    if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
      SimpleModule module = new SimpleModule();
      addSerializers(module);
      addDeserializers(module);
      objectMapper.registerModule(module);
    }

    customizeDefaultFeatures(objectMapper);
    for (Object feature : this.features.keySet()) {
      configureFeature(objectMapper, feature, this.features.get(feature));
    }

    if (this.handlerInstantiator != null) {
      objectMapper.setHandlerInstantiator(this.handlerInstantiator);
    } else if (this.applicationContext != null) {
      objectMapper.setHandlerInstantiator(
          new SpringHandlerInstantiator(this.applicationContext.getAutowireCapableBeanFactory()));
    }
  }