当前位置: 首页>>代码示例>>Java>>正文


Java JsonSerializer.serialize方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonSerializer.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonSerializer.serialize方法的具体用法?Java JsonSerializer.serialize怎么用?Java JsonSerializer.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.JsonSerializer的用法示例。


在下文中一共展示了JsonSerializer.serialize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
	// gen.writeObject(value);
	// String fieldName = gen.getOutputContext().getCurrentName();
	// System.err.println("FieldDetailJsonSerializer serialize: className:" + className);
	try {
		Class<?> clazz;
		String className = anno.className();
		if (className.length() <= 0) {
			clazz = anno.using();
		}
		else {
			clazz = Class.forName(className);
		}
		@SuppressWarnings("unchecked")
		JsonSerializer<Object> serializer = (JsonSerializer<Object>) clazz.newInstance();
		serializer.serialize(value, gen, serializers);
	}
	catch (Exception e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	// System.err.println("JsonDetailJsonSerializer serialize value:" + value + " fieldName:" + fieldName + " type:" + beanProperty.getMember().getGenericType().getTypeName());
	// Object detail = null;
	// gen.writeObject(detail);
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:26,代码来源:FieldDetailJsonSerializer.java

示例2: write

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
void write(Object val, int containedTypeIndex, JsonGenerator gen, SerializerProvider provider) throws IOException {
    if (val != null) {
        if (type.containedTypeCount() > containedTypeIndex) {
            JsonSerializer<Object> ser;
            JavaType containedType = type.containedType(containedTypeIndex);
            if (containedType != null && containedType.hasGenericTypes()) {
                List<JavaType> types = containedType.getBindings().getTypeParameters();
                JavaType[] generics = new JavaType[types.size()];
                for (int i = 0; i < types.size(); i++) {
                    generics[i] = types.get(i);
                }
                JavaType adjusted = provider.getTypeFactory().constructSimpleType(val.getClass(), generics);
                ser = provider.findTypedValueSerializer(adjusted, true, null);
            } else {
                ser = provider.findTypedValueSerializer(val.getClass(), true, null);
            }
            ser.serialize(val, gen, provider);
        } else {
            gen.writeObject(val);
        }
    } else {
        gen.writeNull();
    }
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:25,代码来源:HListSerializer.java

示例3: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    Object obj = toJavaObj(value);
    if (obj == null) {
        provider.getDefaultNullValueSerializer().serialize(null, gen, provider);
    } else {
        JsonSerializer<Object> ser;
        try {
            JavaType emulated = emulatedJavaType(type, provider.getTypeFactory());
            if (emulated.getRawClass() != Object.class) {
                ser = provider.findTypedValueSerializer(emulated, true, null);
            } else {
                ser = provider.findTypedValueSerializer(obj.getClass(), true, null);
            }
        } catch (Exception ignore) {
            ser = provider.findTypedValueSerializer(obj.getClass(), true, null);
        }
        ser.serialize(obj, gen, provider);
    }
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:21,代码来源:ValueSerializer.java

示例4: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(
        Resources value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException
{
    // Extracted the actual data inside of the Resources object that we care about
    Object content = value.getContent();

    // Instead of all of the Resources member variables, etc.
    // Just mashall the actual content into the JSON
    JsonSerializer<Object> s = provider.findValueSerializer(content.getClass(), null);
    s.serialize(content, jgen, provider);
}
 
开发者ID:ftsakiris,项目名称:async-engine,代码行数:14,代码来源:ResourcesMapper.java

示例5: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(StringInDatabase obj, JsonGenerator jgen, SerializerProvider sp) throws IOException {

  if (sp.getActiveView().isAssignableFrom(View.Db.class)) {
    jgen.writeString(obj.stringInDatabase());
  } else {
    final JsonSerializer<Object> beanSerializer = JsonHelper.getBeanSerializer(sp, obj.getClass());
    beanSerializer.serialize(obj, jgen, sp);
  }
}
 
开发者ID:atgse,项目名称:sam,代码行数:11,代码来源:StringInDatabaseSerializer.java

示例6: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(Resources value, JsonGenerator jgen,
		SerializerProvider provider) throws IOException,
		JsonProcessingException {
	// Extracted the actual data inside of the Resources object
	// that we care about (e.g., the list of Video objects)
	Object content = value.getContent();
	// Instead of all of the Resources member variables, etc.
	// Just mashall the actual content (Videos) into the JSON
	JsonSerializer<Object> s = provider.findValueSerializer(
			content.getClass(), null);
	s.serialize(content, jgen, provider);
}
 
开发者ID:juleswhite,项目名称:CSX278,代码行数:14,代码来源:ResourcesMapper.java

示例7: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(ExtractionFunctionDimension value, JsonGenerator gen, SerializerProvider provider)
        throws IOException {

    if (!LookupDimension.class.isInstance(value) && !RegisteredLookupDimension.class.isInstance(value)) {
        throw new TypeMismatchException("Lookup dimension serializer was given a non-lookup dimension.");
    }

    Optional<ExtractionFunction> extractionFunction = value.getExtractionFunction();

    // Use DimensionToDefaultDimensionSpec serializer if LookupDimension does not contain any namespace or lookups
    // or is not the inner most query
    if (!extractionFunction.isPresent() || SerializerUtil.hasInnerQuery(gen)) {
        JsonSerializer<Object> dimensionSerializer = provider.findValueSerializer(Dimension.class);
        dimensionSerializer.serialize(value, gen, provider);
        return;
    }

    String apiName = value.getApiName();
    String physicalName = SerializerUtil.findPhysicalName(value, gen).orElseThrow(() -> {
                LOG.error(ErrorMessageFormat.PHYSICAL_NAME_NOT_FOUND.logFormat(value.getApiName()));
                return new IllegalStateException(ErrorMessageFormat.PHYSICAL_NAME_NOT_FOUND.format());
            }
    );

    gen.writeObject(new ExtractionDimensionSpec(physicalName, apiName, extractionFunction.get()));
}
 
开发者ID:yahoo,项目名称:fili,代码行数:28,代码来源:LookupDimensionToDimensionSpec.java

示例8: serializeContents

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serializeContents(Object value, JsonGenerator jgen, SerializerProvider provider)
    throws IOException
{
    JsonPropertyOrder order = value.getClass().getAnnotation(JsonPropertyOrder.class);
    String[] propOrder = (order == null) ? null : order.value();

    if (propOrder == null) {
        throw new IllegalStateException("Bean must declare JsonPropertyOrder!");
    }

    if (propOrder.length == 0) {
        return;
    }

    int i = 0;
    try {
        do {
            Field field = value.getClass().getDeclaredField(propOrder[i]);
            ReflectionUtils.makeAccessible(field);
            Object elem = field.get(value);
            if (elem == null) {
                provider.defaultSerializeNull(jgen);
            }
            else {
                Class<?> cc = elem.getClass();
                JsonSerializer<Object> serializer = provider.findValueSerializer(cc, null);
                serializer.serialize(elem, jgen, provider);
            }
            ++i;
        }
        while (i < propOrder.length);
    }
    catch (Exception e) {
        // [JACKSON-55] Need to add reference information
        wrapAndThrow(provider, e, value, i);
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:39,代码来源:BeanAsArraySerializer.java

示例9: serialize

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@Override
public void serialize(
  JsonValues value, JsonGenerator jgen, SerializerProvider provider
) throws IOException, JsonProcessingException {
  JsonSerializer<Object> serializer = provider.findValueSerializer(value.values.getClass(), null);
  serializer.serialize(value.values, jgen, provider);
}
 
开发者ID:shunfei,项目名称:DCMonitor,代码行数:8,代码来源:JsonValues.java

示例10: serializeNotNullValue

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
public void serializeNotNullValue( JsonSerializer serializer, T value, JsonGenerator generator, SerializerProvider provider ) throws IOException, JsonProcessingException {
    serializer.serialize( value, generator, provider );
}
 
开发者ID:NyBatis,项目名称:NyBatisCore,代码行数:4,代码来源:AbstractJsonSerializer.java

示例11: writeObject

import com.fasterxml.jackson.databind.JsonSerializer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
void writeObject(Object obj) throws IOException {
  jgen.writeStartObject();

  Class cls = obj.getClass();
  while(!cls.equals(Object.class)) {
    Field[] fields = getDeclaredFields(cls);
    for(Field field : fields) {
      try {
        field.setAccessible(true);

        //if the field has a serializer annotation on it, serialize with it
        if(fieldAllowed(field, obj.getClass())) {
          Object val = readField(obj, field);
          if(!valueAllowed(val, obj.getClass())) {
            continue;
          }

          String name = getFieldName(field);
          jgen.writeFieldName(name);

          JsonSerializer fieldSerializer = annotatedWithJsonSerialize(field);
          if(fieldSerializer != null) {
            fieldSerializer.serialize(val, jgen, serializerProvider);
          } else if(customSerializersMap != null && val != null) {
            JsonSerializer<Object> serializer = customSerializersMap.get(val.getClass());
            if(serializer != null) {
              serializer.serialize(val, jgen, serializerProvider);
            } else {
              new JsonWriter(jgen, result, currentMatch, currentPath, path, field, serializerProvider).write(name, val);
            }
          } else {
            new JsonWriter(jgen, result, currentMatch, currentPath, path, field, serializerProvider).write(name, val);
          }
        }
      } catch(IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
    cls = cls.getSuperclass();
  }

  jgen.writeEndObject();
}
 
开发者ID:monitorjbl,项目名称:json-view,代码行数:45,代码来源:JsonViewSerializer.java


注:本文中的com.fasterxml.jackson.databind.JsonSerializer.serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。