com.fasterxml.jackson.databind.ser.BeanSerializerFactory源码实例Demo

类com.fasterxml.jackson.databind.ser.BeanSerializerFactory源码实例Demo

下面列出了com.fasterxml.jackson.databind.ser.BeanSerializerFactory 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: kogito-runtimes   文件: ExtensionSerializer.java
@Override
public void serialize(Extension extension,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    String extensionId = extension.getExtensionId();

    if (extensionsMap.containsKey(extensionId)) {
        // serialize after setting default bean values...
        BeanSerializerFactory.instance.createSerializer(provider,
                                                        TypeFactory.defaultInstance().constructType(extensionsMap.get(extensionId))).serialize(extension,
                                                                                                                                               gen,
                                                                                                                                               provider);
    } else {
        throw new IllegalArgumentException("Extension handler not registered for: " + extensionId);
    }
}
 
源代码2 项目: endpoints-java   文件: ObjectMapperUtil.java
/**
 * Creates an Endpoints standard object mapper that allows unquoted field names and unknown
 * properties.
 *
 * Note on unknown properties: When Apiary FE supports a strict mode where properties
 * are checked against the schema, BE can just ignore unknown properties.  This way, FE does
 * not need to filter out everything that the BE doesn't understand.  Before that's done,
 * a property name with a typo in it, for example, will just be ignored by the BE.
 */
public static ObjectMapper createStandardObjectMapper(ApiSerializationConfig config) {
  ObjectMapper objectMapper = new ObjectMapper()
      .configure(JsonParser.Feature.ALLOW_COMMENTS, true)
      .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
      .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .setBase64Variant(Base64Variants.MODIFIED_FOR_URL)
      .setSerializerFactory(
          BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier()));
  AnnotationIntrospector pair = EndpointsFlag.JSON_USE_JACKSON_ANNOTATIONS.isEnabled()
      ? AnnotationIntrospector.pair(
          new ApiAnnotationIntrospector(config),
          new JacksonAnnotationIntrospector())
      : new ApiAnnotationIntrospector(config);
  objectMapper.setAnnotationIntrospector(pair);
  return objectMapper;
}
 
@Override
public void serialize(BlockHeaderExtensions blockHeaderExtensions, JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException {
    JavaType javaType = serializerProvider.constructType(CommentPayoutBeneficiaries.class);
    BeanDescription beanDesc = serializerProvider.getConfig().introspect(javaType);
    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanSerializer(serializerProvider,
            javaType, beanDesc);

    jsonGenerator.writeStartArray();

    if (blockHeaderExtensions instanceof Version) {
        jsonGenerator.writeNumber(BlockHeaderExtentsionsType.VERSION.ordinal());
        serializer.serialize((Version) blockHeaderExtensions, jsonGenerator, serializerProvider);
    } else if (blockHeaderExtensions instanceof HardforkVersionVote) {
        jsonGenerator.writeNumber(BlockHeaderExtentsionsType.HARDFORK_VERSION_VOTE.ordinal());
        serializer.serialize((HardforkVersionVote) blockHeaderExtensions, jsonGenerator, serializerProvider);
    } else {
        throw new IllegalArgumentException(
                "Unknown extension type class '" + blockHeaderExtensions.getClass().getSimpleName() + "'.");
    }

    jsonGenerator.writeEndArray();
}
 
@Override
public void serialize(CommentOptionsExtension commentOptionsExtension, JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException {
    if (!(commentOptionsExtension instanceof CommentPayoutBeneficiaries)) {
        throw new IllegalArgumentException(
                "Unknown extension type class '" + commentOptionsExtension.getClass().getSimpleName() + "'.");
    }

    jsonGenerator.writeStartArray();
    jsonGenerator.writeNumber(CommentOptionsExtensionsType.COMMENT_PAYOUT_BENEFICIARIES.ordinal());

    JavaType javaType = serializerProvider.constructType(CommentPayoutBeneficiaries.class);
    BeanDescription beanDesc = serializerProvider.getConfig().introspect(javaType);
    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanSerializer(serializerProvider,
            javaType, beanDesc);
    serializer.serialize((CommentPayoutBeneficiaries) commentOptionsExtension, jsonGenerator, serializerProvider);

    jsonGenerator.writeEndArray();
}
 
源代码5 项目: typescript-generator   文件: Jackson2Parser.java
private BeanHelper getBeanHelper(Class<?> beanClass) {
    if (beanClass == null) {
        return null;
    }
    if (beanClass == Enum.class) {
        return null;
    }
    try {
        final DefaultSerializerProvider.Impl serializerProvider1 = (DefaultSerializerProvider.Impl) objectMapper.getSerializerProvider();
        final DefaultSerializerProvider.Impl serializerProvider2 = serializerProvider1.createInstance(objectMapper.getSerializationConfig(), objectMapper.getSerializerFactory());
        final JavaType simpleType = objectMapper.constructType(beanClass);
        final JsonSerializer<?> jsonSerializer = BeanSerializerFactory.instance.createSerializer(serializerProvider2, simpleType);
        if (jsonSerializer == null) {
            return null;
        }
        if (jsonSerializer instanceof BeanSerializer) {
            return new BeanHelper((BeanSerializer) jsonSerializer);
        } else {
            return null;
        }
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    }
}
 
源代码6 项目: presto   文件: AbstractTypedJacksonModule.java
@SuppressWarnings("unchecked")
private static <T> JsonSerializer<T> createSerializer(SerializerProvider provider, Class<?> type)
        throws JsonMappingException
{
    JavaType javaType = provider.constructType(type);
    return (JsonSerializer<T>) BeanSerializerFactory.instance.createSerializer(provider, javaType);
}
 
源代码7 项目: kogito-runtimes   文件: SubflowStateSerializer.java
@Override
public void serialize(SubflowState subflowState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for end state
    subflowState.setType(DefaultState.Type.SUBFLOW);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(SubflowState.class)).serialize(subflowState,
                                                                                                                               gen,
                                                                                                                               provider);
}
 
源代码8 项目: kogito-runtimes   文件: InjectStateSerializer.java
@Override
public void serialize(InjectState relayState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for relay state
    relayState.setType(DefaultState.Type.INJECT);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
            TypeFactory.defaultInstance().constructType(InjectState.class)).serialize(relayState,
            gen,
            provider);
}
 
源代码9 项目: kogito-runtimes   文件: ForEachStateSerializer.java
@Override
public void serialize(ForEachState forEachState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for foreach state
    forEachState.setType(DefaultState.Type.FOREACH);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
            TypeFactory.defaultInstance().constructType(ForEachState.class)).serialize(forEachState,
            gen,
            provider);
}
 
源代码10 项目: kogito-runtimes   文件: EventStateSerializer.java
@Override
public void serialize(EventState eventState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for end state
    eventState.setType(DefaultState.Type.EVENT);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(EventState.class)).serialize(eventState,
                                                                                                                             gen,
                                                                                                                             provider);
}
 
源代码11 项目: kogito-runtimes   文件: CallbackStateSerializer.java
@Override
public void serialize(CallbackState callbackState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for callback state
    callbackState.setType(DefaultState.Type.CALLBACK);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
            TypeFactory.defaultInstance().constructType(CallbackState.class)).serialize(callbackState,
            gen,
            provider);
}
 
源代码12 项目: kogito-runtimes   文件: OperationStateSerializer.java
@Override
public void serialize(OperationState operationState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for delay state
    operationState.setType(DefaultState.Type.OPERATION);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(OperationState.class)).serialize(operationState,
                                                                                                                                 gen,
                                                                                                                                 provider);
}
 
@Override
public void serialize(EventDefinition triggerEvent,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(EventDefinition.class)).serialize(triggerEvent,
                                                                                                                               gen,
                                                                                                                               provider);
}
 
源代码14 项目: kogito-runtimes   文件: SwitchStateSerializer.java
@Override
public void serialize(SwitchState switchState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for end state
    switchState.setType(DefaultState.Type.SWITCH);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(SwitchState.class)).serialize(switchState,
                                                                                                                              gen,
                                                                                                                              provider);
}
 
源代码15 项目: kogito-runtimes   文件: ParallelStateSerializer.java
@Override
public void serialize(ParallelState parallelState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for end state
    parallelState.setType(DefaultState.Type.PARALLEL);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(ParallelState.class)).serialize(parallelState,
                                                                                                                                gen,
                                                                                                                                provider);
}
 
源代码16 项目: kogito-runtimes   文件: DelayStateSerializer.java
@Override
public void serialize(DelayState delayState,
                      JsonGenerator gen,
                      SerializerProvider provider) throws IOException {

    // set defaults for delay state
    delayState.setType(DefaultState.Type.DELAY);

    // serialize after setting default bean values...
    BeanSerializerFactory.instance.createSerializer(provider,
                                                    TypeFactory.defaultInstance().constructType(DelayState.class)).serialize(delayState,
                                                                                                                             gen,
                                                                                                                             provider);
}
 
源代码17 项目: emissary   文件: JsonOutputFilter.java
@Override
public void serialize(IBaseDataObject ibdo, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeStartObject();
    JavaType javaType = provider.constructType(IBaseDataObject.class);
    BeanDescription beanDesc = provider.getConfig().introspect(javaType);
    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanOrAddOnSerializer(provider, javaType, beanDesc,
            provider.isEnabled(MapperFeature.USE_STATIC_TYPING));

    // add some custom fields here
    jgen.writeObjectField("id", dropOffUtil.getBestIdFrom(ibdo));
    jgen.writeObjectField("processedTimestamp", TimeUtil.getCurrentDateFullISO8601());

    serializer.unwrappingSerializer(null).serialize(ibdo, jgen, provider);
    jgen.writeEndObject();
}
 
源代码18 项目: tutorials   文件: JacksonJsonViewUnitTest.java
@Test
public void whenUseCustomJsonViewToSerialize_thenCorrect() throws JsonProcessingException {
    final User user = new User(1, "John");
    final SerializerFactory serializerFactory = BeanSerializerFactory.instance.withSerializerModifier(new MyBeanSerializerModifier());

    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializerFactory(serializerFactory);

    final String result = mapper.writerWithView(Views.Public.class)
        .writeValueAsString(user);
    assertThat(result, containsString("JOHN"));
    assertThat(result, containsString("1"));
}
 
private void writeBlockElement(BlockElement element, JsonGenerator gen, SerializerProvider provider) throws IOException {
  JavaType javaType = provider.constructType(element.getClass());
  BeanDescription beanDesc = provider.getConfig().introspect(javaType);
  JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanSerializer(provider, javaType, beanDesc);
  serializer.unwrappingSerializer(null).serialize(element, gen, provider);
}
 
源代码20 项目: caravan   文件: FilterableBeanSerializerModifier.java
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
    FilterableType filterableType = _config.getFilterableType(beanDesc.getBeanClass());
    if (filterableType == null)
        return beanProperties;

    for (final BeanPropertyWriter beanPropertyWriter : beanProperties) {
        final FilterableProperty property = filterableType.getProperty(beanPropertyWriter.getName());
        if (property == null || property.getSerializationFilter() == null)
            continue;

        beanPropertyWriter.assignSerializer(new StdSerializer<Object>(Object.class) {

            private static final long serialVersionUID = 1L;

            @Override
            public void serialize(Object value, JsonGenerator gen, final SerializerProvider provider) throws IOException {
                JsonSerializer<Object> serializer = ConcurrentHashMapValues.getOrAdd(_customSerializers, beanPropertyWriter.getType(),
                        new Func<JsonSerializer<Object>>() {
                            @Override
                            public JsonSerializer<Object> execute() {
                                try {
                                    return BeanSerializerFactory.instance.createSerializer(provider, beanPropertyWriter.getType());
                                } catch (Throwable ex) {
                                    _logger.error("Error occurred when creating custom serializer for type: " + beanPropertyWriter.getType(), ex);
                                    return NullSerializer.instance;
                                }
                            }
                        });

                value = property.getSerializationFilter().filter(property, value);
                if (value == null) {
                    gen.writeNull();
                    return;
                }

                serializer.serialize(value, gen, provider);
            }
        });

        _logger.info("Will apply filter {} for property: {}.", property.getSerializationFilter(), property.name());
    }

    return beanProperties;
}
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法