Java 类org.codehaus.jackson.map.SerializerProvider 实例源码

项目: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);
}
项目:Multipath-Hedera-system-in-Floodlight-controller    文件:OFFeaturesReplyJSONSerializer.java   
/**
 * Performs the serialization of a OFFeaturesReply object
 */
@Override
public void serialize(OFFeaturesReply reply, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
    jGen.writeStartObject();
    jGen.writeNumberField("actions", reply.getActions());
    jGen.writeNumberField("buffers", reply.getBuffers());
    jGen.writeNumberField("capabilities", reply.getCapabilities());
    jGen.writeStringField("datapathId", HexString.toHexString(reply.getDatapathId()));
    jGen.writeNumberField("length", reply.getLength());
    serializer.defaultSerializeField("ports", reply.getPorts(), jGen);
    jGen.writeNumberField("tables", reply.getTables());
    jGen.writeStringField("type", reply.getType().toString());
    jGen.writeNumberField("version", reply.getVersion());
    jGen.writeNumberField("xid", reply.getXid());
    jGen.writeEndObject();
}
项目:Multipath-Hedera-system-in-Floodlight-controller    文件:CumulativeTimeBucketJSONSerializer.java   
/**
  * Performs the serialization of a OneComponentTime object
  */
@Override
public void serialize(CumulativeTimeBucket ctb,
                JsonGenerator jGen,
                SerializerProvider serializer) 
                throws IOException, JsonProcessingException {
    jGen.writeStartObject();
    Timestamp ts = new Timestamp(ctb.getStartTimeNs()/1000000);
    jGen.writeStringField("start-time", ts.toString());
    jGen.writeStringField("current-time", 
      new Timestamp(System.currentTimeMillis()).toString());
    jGen.writeNumberField("total-packets", ctb.getTotalPktCnt());
    jGen.writeNumberField("average", ctb.getAverageProcTimeNs());
    jGen.writeNumberField("min", ctb.getMinTotalProcTimeNs());
    jGen.writeNumberField("max", ctb.getMaxTotalProcTimeNs());
    jGen.writeNumberField("std-dev", ctb.getTotalSigmaProcTimeNs());
    jGen.writeArrayFieldStart("modules");
    for (OneComponentTime oct : ctb.getModules()) {
        serializer.defaultSerializeValue(oct, jGen);
    }
    jGen.writeEndArray();
    jGen.writeEndObject();
}
项目:Multipath-Hedera-system-in-Floodlight-controller    文件:VirtualNetworkSerializer.java   
@Override
public void serialize(VirtualNetwork vNet, JsonGenerator jGen,
        SerializerProvider serializer) throws IOException,
        JsonProcessingException {
    jGen.writeStartObject();

    jGen.writeStringField("name", vNet.name);
    jGen.writeStringField("guid", vNet.guid);
    jGen.writeStringField("gateway", vNet.gateway);

    jGen.writeArrayFieldStart("mac");
    Iterator<MACAddress> hit = vNet.hosts.iterator();
    while (hit.hasNext())
        jGen.writeString(hit.next().toString());
    jGen.writeEndArray();

    jGen.writeEndObject();
}
项目:Multipath-Hedera-system-in-Floodlight-controller    文件:EventHistoryBaseInfoJSONSerializer.java   
/**
 * Performs the serialization of a EventHistory.BaseInfo object
 */
@Override
public void serialize(EventHistoryBaseInfo base_info, JsonGenerator jGen,
                SerializerProvider serializer) 
                throws IOException, JsonProcessingException {
    jGen.writeStartObject();
    jGen.writeNumberField("Idx",    base_info.getIdx());
    Timestamp ts = new Timestamp(base_info.getTime_ms());
    String tsStr = ts.toString();
    while (tsStr.length() < 23) {
        tsStr = tsStr.concat("0");
    }
    jGen.writeStringField("Time", tsStr);
    jGen.writeStringField("State",  base_info.getState().name());
    String acStr = base_info.getAction().name().toLowerCase();
    // Capitalize the first letter
    acStr = acStr.substring(0,1).toUpperCase().concat(acStr.substring(1));
    jGen.writeStringField("Action", acStr);
    jGen.writeEndObject();
}
项目:gravity    文件:MapJsonSerializer.java   
@Override
public void serialize(Map<String, Object> fields, JsonGenerator jgen,
        SerializerProvider provider) throws IOException,
        JsonProcessingException {
    jgen.writeStartObject();
    for (Entry<String, Object> entry : fields.entrySet()) {
        Object objectValue = entry.getValue();
        if (objectValue instanceof Date) {
            Date date = (Date) objectValue;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
            String formattedDate = simpleDateFormat.format(date);
            jgen.writeObjectField(entry.getKey().toString(), formattedDate);
        } else {
            jgen.writeObjectField(entry.getKey().toString(), objectValue);
        }
    }
    jgen.writeEndObject();
}
项目:community-edition-old    文件:SerializerOfCollectionWithPaging.java   
@Override
public void serialize(SerializablePagedCollection pagedCol, JsonGenerator jgen, SerializerProvider provider)
            throws IOException, JsonGenerationException
{
    if (pagedCol != null)
    {
        jgen.writeStartObject();
        jgen.writeFieldName("list");
            jgen.writeStartObject();
            serializePagination(pagedCol, jgen);
            serializeContext(pagedCol, jgen);
            jgen.writeObjectField("entries", pagedCol.getCollection());
            serializeIncludedSource(pagedCol, jgen);
            jgen.writeEndObject(); 
        jgen.writeEndObject();  
    }
}
项目:spring-open    文件:LinkDataSerializer.java   
/**
 * Serializes a LinkData object in JSON.
 *
 * @param linkData the LinkData that is being converted to JSON
 * @param jsonGenerator generator to place the serialized JSON into
 * @param serializerProvider unused but required for method override
 * @throws IOException if the JSON serialization process fails
 */
@Override
public void serialize(final LinkData linkData,
                      final JsonGenerator jsonGenerator,
                      final SerializerProvider serializerProvider)
    throws IOException {

    //
    // TODO: For now, the JSON format of the serialized output should
    // be same as the JSON format of the corresponding class Link.
    // In the future, we will use a single serializer.
    //

    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(TopologyElement.TYPE, linkData.getType());
    jsonGenerator.writeObjectField("src", linkData.getSrc());
    jsonGenerator.writeObjectField("dst", linkData.getDst());
    jsonGenerator.writeObjectFieldStart("stringAttributes");
    for (Entry<String, String> entry : linkData.getAllStringAttributes().entrySet()) {
        jsonGenerator.writeStringField(entry.getKey(), entry.getValue());
    }
    jsonGenerator.writeEndObject();         // stringAttributes
    jsonGenerator.writeEndObject();
}
项目:smartenit    文件:OFFeaturesReplyJSONSerializer.java   
/**
 * Performs the serialization of a OFFeaturesReply object
 */
@Override
public void serialize(OFFeaturesReply reply, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
    jGen.writeStartObject();
    jGen.writeNumberField("actions", reply.getActions());
    jGen.writeNumberField("buffers", reply.getBuffers());
    jGen.writeNumberField("capabilities", reply.getCapabilities());
    jGen.writeStringField("datapathId", HexString.toHexString(reply.getDatapathId()));
    jGen.writeNumberField("length", reply.getLength());
    serializer.defaultSerializeField("ports", reply.getPorts(), jGen);
    jGen.writeNumberField("tables", reply.getTables());
    jGen.writeStringField("type", reply.getType().toString());
    jGen.writeNumberField("version", reply.getVersion());
    jGen.writeNumberField("xid", reply.getXid());
    jGen.writeEndObject();
}
项目:smartenit    文件:VirtualNetworkSerializer.java   
@Override
public void serialize(VirtualNetwork vNet, JsonGenerator jGen,
        SerializerProvider serializer) throws IOException,
        JsonProcessingException {
    jGen.writeStartObject();

    jGen.writeStringField("name", vNet.name);
    jGen.writeStringField("guid", vNet.guid);
    jGen.writeStringField("gateway", vNet.gateway);

    jGen.writeArrayFieldStart("mac");
    Iterator<MACAddress> hit = vNet.hosts.iterator();
    while (hit.hasNext())
        jGen.writeString(hit.next().toString());
    jGen.writeEndArray();

    jGen.writeEndObject();
}
项目:12306-android-Decompile    文件:JSONWrappedObject.java   
public void serialize(JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider)
  throws IOException, JsonProcessingException
{
  if (this._prefix != null)
    paramJsonGenerator.writeRaw(this._prefix);
  if (this._value == null)
    paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
  while (true)
  {
    if (this._suffix != null)
      paramJsonGenerator.writeRaw(this._suffix);
    return;
    if (this._serializationType != null)
    {
      paramSerializerProvider.findTypedValueSerializer(this._serializationType, true, null).serialize(this._value, paramJsonGenerator, paramSerializerProvider);
      continue;
    }
    paramSerializerProvider.findTypedValueSerializer(this._value.getClass(), true, null).serialize(this._value, paramJsonGenerator, paramSerializerProvider);
  }
}
项目:12306-android-Decompile    文件:ObjectNode.java   
public final void serialize(JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider)
  throws IOException, JsonProcessingException
{
  paramJsonGenerator.writeStartObject();
  if (this._children != null)
  {
    Iterator localIterator = this._children.entrySet().iterator();
    while (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      paramJsonGenerator.writeFieldName((String)localEntry.getKey());
      ((BaseJsonNode)localEntry.getValue()).serialize(paramJsonGenerator, paramSerializerProvider);
    }
  }
  paramJsonGenerator.writeEndObject();
}
项目:12306-android-Decompile    文件:JSONPObject.java   
public void serialize(JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider)
  throws IOException, JsonProcessingException
{
  paramJsonGenerator.writeRaw(this._function);
  paramJsonGenerator.writeRaw('(');
  if (this._value == null)
    paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
  while (true)
  {
    paramJsonGenerator.writeRaw(')');
    return;
    if (this._serializationType != null)
    {
      paramSerializerProvider.findTypedValueSerializer(this._serializationType, true, null).serialize(this._value, paramJsonGenerator, paramSerializerProvider);
      continue;
    }
    paramSerializerProvider.findTypedValueSerializer(this._value.getClass(), true, null).serialize(this._value, paramJsonGenerator, paramSerializerProvider);
  }
}
项目:12306-android-Decompile    文件:StdSerializers.java   
public void serialize(Number paramNumber, JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider)
  throws IOException, JsonGenerationException
{
  if ((paramNumber instanceof BigDecimal))
  {
    paramJsonGenerator.writeNumber((BigDecimal)paramNumber);
    return;
  }
  if ((paramNumber instanceof BigInteger))
  {
    paramJsonGenerator.writeNumber((BigInteger)paramNumber);
    return;
  }
  if ((paramNumber instanceof Double))
  {
    paramJsonGenerator.writeNumber(((Double)paramNumber).doubleValue());
    return;
  }
  if ((paramNumber instanceof Float))
  {
    paramJsonGenerator.writeNumber(((Float)paramNumber).floatValue());
    return;
  }
  paramJsonGenerator.writeNumber(paramNumber.toString());
}
项目:stickypunch    文件:WebPushUserSerializer.java   
@Override
public void serialize(WebPushUser value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    jgen.writeStartObject();
    if (value.getDeviceToken().isPresent()) {
        jgen.writeStringField("deviceToken", value.getDeviceToken().get());
    }
    if (value.getActive().isPresent()) {
        jgen.writeBooleanField("isActive", value.getActive().get());
    }
    if (value.getUserId().isPresent()) {
        jgen.writeStringField("userId", value.getUserId().get());
    }
    if (value.getWebsitePushId().isPresent()) {
        jgen.writeStringField("websitePushId", value.getWebsitePushId().get());
    }
    if (value.getActiveTimestamp().isPresent()) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS");
        Date dt = new Date(value.getActiveTimestamp().get());
        String readableDate = sdf.format(dt);
        jgen.writeStringField("activeDate", readableDate);
    }
    jgen.writeEndObject();
}
项目:12306-android-Decompile    文件:ObjectNode.java   
public void serializeWithType(JsonGenerator paramJsonGenerator, SerializerProvider paramSerializerProvider, TypeSerializer paramTypeSerializer)
  throws IOException, JsonProcessingException
{
  paramTypeSerializer.writeTypePrefixForObject(this, paramJsonGenerator);
  if (this._children != null)
  {
    Iterator localIterator = this._children.entrySet().iterator();
    while (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      paramJsonGenerator.writeFieldName((String)localEntry.getKey());
      ((BaseJsonNode)localEntry.getValue()).serialize(paramJsonGenerator, paramSerializerProvider);
    }
  }
  paramTypeSerializer.writeTypeSuffixForObject(this, paramJsonGenerator);
}
项目:archived-net-virt-platform    文件:OFFeaturesReplyJSONSerializer.java   
/**
 * Performs the serialization of a OFFeaturesReply object
 */
@Override
public void serialize(OFFeaturesReply reply, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
    jGen.writeStartObject();
    jGen.writeNumberField("actions", reply.getActions());
    jGen.writeNumberField("buffers", reply.getBuffers());
    jGen.writeNumberField("capabilities", reply.getCapabilities());
    jGen.writeStringField("datapathId", HexString.toHexString(reply.getDatapathId()));
    jGen.writeNumberField("length", reply.getLength());
    serializer.defaultSerializeField("ports", reply.getPorts(), jGen);
    jGen.writeNumberField("tables", reply.getTables());
    jGen.writeStringField("type", reply.getType().toString());
    jGen.writeNumberField("version", reply.getVersion());
    jGen.writeNumberField("xid", reply.getXid());
    jGen.writeEndObject();
}
项目:archived-net-virt-platform    文件:TunnelLinkStatusSerializer.java   
@Override
public void serialize(TunnelLinkStatus status, JsonGenerator jGen,
        SerializerProvider serializer) throws IOException,
        JsonProcessingException {
    String resultString;
    if (status == TunnelLinkStatus.UP)
        resultString = "up";
    else if (status == TunnelLinkStatus.DOWN)
        resultString = "down";
    else if (status == TunnelLinkStatus.NOT_ENABLED)
        resultString = "disabled";
    else if (status == TunnelLinkStatus.NOT_ACTIVE)
        resultString = "not active";
    else resultString = "unknown";

    jGen.writeString(resultString);
}
项目:12306-android-Decompile    文件:ObjectArraySerializer.java   
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType)
  throws JsonMappingException
{
  ObjectNode localObjectNode = createSchemaNode("array", true);
  Class localClass;
  if (paramType != null)
  {
    JavaType localJavaType = paramSerializerProvider.constructType(paramType);
    if (localJavaType.isArrayType())
    {
      localClass = ((ArrayType)localJavaType).getContentType().getRawClass();
      if (localClass != Object.class)
        break label59;
      localObjectNode.put("items", JsonSchema.getDefaultSchemaNode());
    }
  }
  return localObjectNode;
  label59: JsonSerializer localJsonSerializer = paramSerializerProvider.findValueSerializer(localClass, this._property);
  if ((localJsonSerializer instanceof SchemaAware));
  for (JsonNode localJsonNode = ((SchemaAware)localJsonSerializer).getSchema(paramSerializerProvider, null); ; localJsonNode = JsonSchema.getDefaultSchemaNode())
  {
    localObjectNode.put("items", localJsonNode);
    return localObjectNode;
  }
}
项目:hadoop    文件:DefaultAnonymizingRumenSerializer.java   
public void serialize(AnonymizableDataType object, JsonGenerator jGen, 
                      SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object val = object.getAnonymizedValue(statePool, conf);
  // output the data if its a string
  if (val instanceof String) {
    jGen.writeString(val.toString());
  } else {
    // let the mapper (JSON generator) handle this anonymized object.
    jGen.writeObject(val);
  }
}
项目:hadoop    文件:DefaultRumenSerializer.java   
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object data = object.getValue();
  if (data instanceof String) {
    jGen.writeString(data.toString());
  } else {
    jGen.writeObject(data);
  }
}
项目:jwala    文件:MediaTypeSerializer.java   
@Override
public void serialize(final MediaType mediaType, final JsonGenerator generator, final SerializerProvider provider)
        throws IOException {
    generator.writeStartObject();
    generator.writeFieldName("name");
    generator.writeString(mediaType.name());
    generator.writeFieldName("displayName");
    generator.writeString(mediaType.getDisplayName());
    generator.writeEndObject();
}
项目:aliyun-oss-hadoop-fs    文件:DefaultAnonymizingRumenSerializer.java   
public void serialize(AnonymizableDataType object, JsonGenerator jGen, 
                      SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object val = object.getAnonymizedValue(statePool, conf);
  // output the data if its a string
  if (val instanceof String) {
    jGen.writeString(val.toString());
  } else {
    // let the mapper (JSON generator) handle this anonymized object.
    jGen.writeObject(val);
  }
}
项目:aliyun-oss-hadoop-fs    文件:DefaultRumenSerializer.java   
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object data = object.getValue();
  if (data instanceof String) {
    jGen.writeString(data.toString());
  } else {
    jGen.writeObject(data);
  }
}
项目:big-c    文件:DefaultAnonymizingRumenSerializer.java   
public void serialize(AnonymizableDataType object, JsonGenerator jGen, 
                      SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object val = object.getAnonymizedValue(statePool, conf);
  // output the data if its a string
  if (val instanceof String) {
    jGen.writeString(val.toString());
  } else {
    // let the mapper (JSON generator) handle this anonymized object.
    jGen.writeObject(val);
  }
}
项目:big-c    文件:DefaultRumenSerializer.java   
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object data = object.getValue();
  if (data instanceof String) {
    jGen.writeString(data.toString());
  } else {
    jGen.writeObject(data);
  }
}
项目:osmp    文件:DefaultObjectMapper.java   
@Override
public void serialize(Date arg0, JsonGenerator arg1,
        SerializerProvider arg2) throws IOException,
        JsonProcessingException {
        arg1.writeString(DateFormatUtils.format(arg0, "yyyy-MM-dd HH:mm:ss", Locale.CHINA));

}
项目:playground    文件:IntervalSerializer.java   
@Override
public void serialize(
        final Interval interval,
        final JsonGenerator jgen,
        final SerializerProvider provider) throws IOException, JsonProcessingException
{
    if (interval == null)
    {
        jgen.writeNull();
        return;
    }

    jgen.writeString(interval.getStartMillis() + "-" + interval.getEndMillis());
}
项目:playground    文件:NullKeysAsEmptyStringsSerializer.java   
@Override
public void serialize(
        final Object nullKey,
        final JsonGenerator jsonGenerator,
        final SerializerProvider unused) throws IOException, JsonProcessingException {
    jsonGenerator.writeFieldName("");
}
项目:playground    文件:InstantSerializer.java   
@Override
public void serialize(
        final Instant dateTime,
        final JsonGenerator jgen,
        final SerializerProvider provider) throws IOException, JsonProcessingException
{
    if (dateTime == null)
    {
        jgen.writeNull();
        return;
    }

    final DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    jgen.writeString(dateTime.toString(formatter));
}
项目:playground    文件:DurationSerializer.java   
@Override
public void serialize(
        final Duration duration,
        final JsonGenerator jgen,
        final SerializerProvider provider) throws IOException, JsonProcessingException
{
    if (duration == null)
    {
        jgen.writeNull();
        return;
    }

    final PeriodFormatter formatter = ISOPeriodFormat.standard();
    jgen.writeString(duration.toPeriod().toString(formatter));
}
项目:playground    文件:LocalDateSerializer.java   
@Override
public void serialize(
        final LocalDate date,
        final JsonGenerator jgen,
        final SerializerProvider provider) throws IOException, JsonProcessingException
{
    if (date == null)
    {
        jgen.writeNull();
        return;
    }

    jgen.writeString(date.toString());
}
项目:gluu    文件:GluuCustomPersonListSerializer.java   
@Override
public void serialize(ScimPerson scimPerson, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("userName");
            /*
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            */
        }

        JsonNode rootNode = mapper.convertValue(scimPerson, JsonNode.class);

        processNodes(null, rootNode, mapper, scimPerson, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
项目:gluu    文件:ListResponseGroupSerializer.java   
@Override
public void serialize(Group group, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        // attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(mapper.readValue(attributesArray, String[].class))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("displayName");
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            attributes.add("meta.resourceType");
        }

        JsonNode rootNode = mapper.convertValue(group, JsonNode.class);

        processNodes(null, rootNode, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
项目:gluu    文件:ListResponseUserSerializer.java   
@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        // attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(mapper.readValue(attributesArray, String[].class))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("userName");
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            attributes.add("meta.resourceType");
        }

        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);

        processNodes(null, rootNode, mapper, user, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
项目:gluu    文件:ListResponseFidoDeviceSerializer.java   
@Override
public void serialize(FidoDevice fidoDevice, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("userId");
            attributes.add("displayName");
               attributes.add("meta.created");
               attributes.add("meta.lastModified");
               attributes.add("meta.location");
               attributes.add("meta.version");
            attributes.add("meta.resourceType");
        }

        JsonNode rootNode = mapper.convertValue(fidoDevice, JsonNode.class);

        processNodes(null, rootNode, mapper, fidoDevice, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
项目:gluu    文件:GluuGroupListSerializer.java   
@Override
public void serialize(ScimGroup scimGroup, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("displayName");
            /*
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            attributes.add("meta.resourceType");
            */
        }

        JsonNode rootNode = mapper.convertValue(scimGroup, JsonNode.class);

        processNodes(null, rootNode, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
项目:Camel    文件:MultiSelectPicklistSerializer.java   
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {

    // get Picklist enum element class from array class
    Class<?> arrayClass = value.getClass();
    final Class<?> aClass = arrayClass.getComponentType();

    try {

        Method getterMethod = aClass.getMethod("value");
        final int length = Array.getLength(value);

        // construct a string of form value1;value2;...
        final StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < length; i++) {
            buffer.append((String) getterMethod.invoke(Array.get(value, i)));
            if (i < (length - 1)) {
                buffer.append(';');
            }
        }

        jgen.writeString(buffer.toString());

    } catch (Exception e) {
        throw new JsonGenerationException(
                String.format("Exception writing pick list value %s of type %s: %s",
                        value, value.getClass().getName(), e.getMessage()), e);
    }
}
项目: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;
  }
}
项目:apex-core    文件:AppPackage.java   
@Override
public void serialize(
    PropertyInfo propertyInfo, JsonGenerator jgen, SerializerProvider provider)
  throws IOException, JsonProcessingException
{
  if (provideDescription) {
    jgen.writeStartObject();
    jgen.writeStringField("value", propertyInfo.value);
    jgen.writeStringField("description", propertyInfo.description);
    jgen.writeEndObject();
  } else {
    jgen.writeString(propertyInfo.value);
  }
}