Java 类org.codehaus.jackson.map.ser.std.SerializerBase 实例源码

项目:apex-core    文件:JsonStreamCodec.java   
public JsonStreamCodec(Map<Class<?>, Class<? extends StringCodec<?>>> codecs)
{
  JacksonObjectMapperProvider jomp = new JacksonObjectMapperProvider();
  if (codecs != null) {
    for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry: codecs.entrySet()) {
      try {
        @SuppressWarnings("unchecked")
        final StringCodec<Object> codec = (StringCodec<Object>)entry.getValue().newInstance();
        jomp.addSerializer(new SerializerBase(entry.getKey())
        {
          @Override
          public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException
          {
            jgen.writeString(codec.toString(value));
          }

        });
      } catch (Exception ex) {
        logger.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
      }
    }
  }
  mapper = jomp.getContext(null);
}
项目:apex-core    文件:StramWebServices.java   
@SuppressWarnings({"rawtypes", "unchecked"})
private void init()
{
  //clear content type
  httpResponse.setContentType(null);
  if (!initialized) {
    Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
    StringCodecs.loadConverters(codecs);
    if (codecs != null) {
      SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
      for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
        try {
          final StringCodec<Object> codec = (StringCodec<Object>)entry.getValue().newInstance();
          sm.addSerializer(new SerializerBase(entry.getKey())
          {
            @Override
            public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException
            {
              jgen.writeString(codec.toString(value));
            }

          });
        } catch (Exception ex) {
          LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
        }
      }

      objectMapper.registerModule(sm);
    }
    initialized = true;
  }
}
项目:spring-open    文件:IntentResource.java   
/**
 * Constructs an IntentResource.
 * <p/>
 * A custom serializer for {@link IntentId} is automatically registered,
 * because IntentId can't be serialized by default.
 */
public IntentResource() {
    intentSerializers = new CustomSerializerHelper();
    intentSerializers.addSerializer(IntentId.class,
        new SerializerBase<IntentId>(IntentId.class) {
            @Override
            public void serialize(IntentId id, JsonGenerator jGen,
                    SerializerProvider sp) throws IOException,
                    JsonProcessingException {
                jGen.writeString(id.toString());
            }
        });
}
项目:spring-open    文件:FlowResource.java   
/**
 * Constructs a FlowResource.
 * <p/>
 * A custom serializer for {@link FlowId} is automatically registered,
 * because FlowId can't be serialized by default.
 */
public FlowResource() {
    flowSerializers = new CustomSerializerHelper();
    flowSerializers.addSerializer(FlowId.class, new SerializerBase<FlowId>(FlowId.class) {
        @Override
        public void serialize(FlowId flowId, JsonGenerator jgen,
                SerializerProvider provider) throws IOException,
                JsonGenerationException {
            jgen.writeString(flowId.toString());
        }
    });
}
项目:spring-open    文件:MatchActionResource.java   
/**
 * Constructs a MatchActionResource.
 * <p/>
 * A custom serializer for {@link MatchActionId} is automatically
 * registered, because MatchActionId can't be serialized by default.
 */
public MatchActionResource() {
    matchActionSerializers = new CustomSerializerHelper();
    matchActionSerializers.addSerializer(MatchActionId.class,
            new SerializerBase<MatchActionId>(MatchActionId.class) {
        @Override
        public void serialize(MatchActionId id, JsonGenerator jGen, SerializerProvider sp)
                throws IOException, JsonProcessingException {
            jGen.writeString(id.toString());
        }
    });
}