com.fasterxml.jackson.databind.JsonSerializer.handledType()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中com.fasterxml.jackson.databind.JsonSerializer.handledType()方法的一些代码示例,展示了JsonSerializer.handledType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonSerializer.handledType()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonSerializer
类名称:JsonSerializer
方法名:handledType

JsonSerializer.handledType介绍

[英]Method for accessing type of Objects this serializer can handle. Note that this information is not guaranteed to be exact -- it may be a more generic (super-type) -- but it should not be incorrect (return a non-related type).

Default implementation will return null, which essentially means same as returning Object.class would; that is, that nothing is known about handled type.
[中]

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Configure custom serializers. Each serializer is registered for the type
  3. * returned by {@link JsonSerializer#handledType()}, which must not be {@code null}.
  4. * @see #serializersByType(Map)
  5. */
  6. public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) {
  7. for (JsonSerializer<?> serializer : serializers) {
  8. Class<?> handledType = serializer.handledType();
  9. if (handledType == null || handledType == Object.class) {
  10. throw new IllegalArgumentException("Unknown handled type in " + serializer.getClass().getName());
  11. }
  12. this.serializers.put(serializer.handledType(), serializer);
  13. }
  14. return this;
  15. }

代码示例来源:origin: org.springframework/spring-web

  1. /**
  2. * Configure custom serializers. Each serializer is registered for the type
  3. * returned by {@link JsonSerializer#handledType()}, which must not be {@code null}.
  4. * @see #serializersByType(Map)
  5. */
  6. public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) {
  7. for (JsonSerializer<?> serializer : serializers) {
  8. Class<?> handledType = serializer.handledType();
  9. if (handledType == null || handledType == Object.class) {
  10. throw new IllegalArgumentException("Unknown handled type in " + serializer.getClass().getName());
  11. }
  12. this.serializers.put(serializer.handledType(), serializer);
  13. }
  14. return this;
  15. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.StdSerializer'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: redisson/redisson

  1. throws IOException
  2. Class<?> clz = handledType();
  3. if (clz == null) {
  4. clz = value.getClass();

代码示例来源:origin: io.airlift/json

  1. public <T> void bindSerializer(JsonSerializer<T> jsonSerializer)
  2. {
  3. requireNonNull(jsonSerializer, "jsonSerializer is null");
  4. Class<?> type = jsonSerializer.handledType();
  5. requireNonNull(type, "jsonSerializer.handledType is null");
  6. Preconditions.checkArgument(type == Object.class, "jsonSerializer.handledType can not be Object.class");
  7. serializerMapBinder.addBinding(type).toInstance(jsonSerializer);
  8. }
  9. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

  1. /**
  2. * Configure custom serializers. Each serializer is registered for the type
  3. * returned by {@link JsonSerializer#handledType()}, which must not be {@code null}.
  4. * @see #serializersByType(Map)
  5. */
  6. public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) {
  7. for (JsonSerializer<?> serializer : serializers) {
  8. Class<?> handledType = serializer.handledType();
  9. if (handledType == null || handledType == Object.class) {
  10. throw new IllegalArgumentException("Unknown handled type in " + serializer.getClass().getName());
  11. }
  12. this.serializers.put(serializer.handledType(), serializer);
  13. }
  14. return this;
  15. }

代码示例来源:origin: com.proofpoint.platform/json

  1. public <T> void bindSerializer(JsonSerializer<T> jsonSerializer)
  2. {
  3. requireNonNull(jsonSerializer, "jsonSerializer is null");
  4. Class<?> type = jsonSerializer.handledType();
  5. requireNonNull(type, "jsonSerializer.handledType is null");
  6. Preconditions.checkArgument(type == Object.class, "jsonSerializer.handledType can not be Object.class");
  7. serializerMapBinder.addBinding(type).toInstance(jsonSerializer);
  8. }
  9. }

代码示例来源:origin: com.teradata.airlift/json

  1. public <T> void bindSerializer(JsonSerializer<T> jsonSerializer)
  2. {
  3. Preconditions.checkNotNull(jsonSerializer, "jsonSerializer is null");
  4. Class<?> type = jsonSerializer.handledType();
  5. Preconditions.checkNotNull(type, "jsonSerializer.handledType is null");
  6. Preconditions.checkArgument(type == Object.class, "jsonSerializer.handledType can not be Object.class");
  7. serializerMapBinder.addBinding(type).toInstance(jsonSerializer);
  8. }
  9. }

代码示例来源:origin: airlift/airlift

  1. public <T> void bindSerializer(JsonSerializer<T> jsonSerializer)
  2. {
  3. requireNonNull(jsonSerializer, "jsonSerializer is null");
  4. Class<?> type = jsonSerializer.handledType();
  5. requireNonNull(type, "jsonSerializer.handledType is null");
  6. Preconditions.checkArgument(type == Object.class, "jsonSerializer.handledType can not be Object.class");
  7. serializerMapBinder.addBinding(type).toInstance(jsonSerializer);
  8. }
  9. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Configure custom serializers. Each serializer is registered for the type
  3. * returned by {@link JsonSerializer#handledType()}, which must not be {@code null}.
  4. * @see #serializersByType(Map)
  5. */
  6. public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) {
  7. for (JsonSerializer<?> serializer : serializers) {
  8. Class<?> handledType = serializer.handledType();
  9. if (handledType == null || handledType == Object.class) {
  10. throw new IllegalArgumentException("Unknown handled type in " + serializer.getClass().getName());
  11. }
  12. this.serializers.put(serializer.handledType(), serializer);
  13. }
  14. return this;
  15. }

代码示例来源:origin: com.bbossgroups/bboss-mvc

  1. /**
  2. * Configure custom serializers. Each serializer is registered for the type
  3. * returned by {@link JsonSerializer#handledType()}, which must not be
  4. * {@code null}.
  5. * @see #serializersByType(Map)
  6. */
  7. public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) {
  8. if (serializers != null) {
  9. for (JsonSerializer<?> serializer : serializers) {
  10. Class<?> handledType = serializer.handledType();
  11. if (handledType == null || handledType == Object.class) {
  12. throw new IllegalArgumentException("Unknown handled type in " + serializer.getClass().getName());
  13. }
  14. this.serializers.put(serializer.handledType(), serializer);
  15. }
  16. }
  17. return this;
  18. }

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

  1. throws IOException, JsonProcessingException
  2. Class<?> clz = handledType();
  3. if (clz == null) {
  4. clz = value.getClass();

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

  1. throws IOException, JsonProcessingException
  2. Class<?> clz = handledType();
  3. if (clz == null) {
  4. clz = value.getClass();

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.StdSerializer'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.SerializerBase'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.StdSerializer'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.StdSerializer'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.StdSerializer'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: Nextdoor/bender

  1. /**
  2. * Method for adding given serializer for type that {@link JsonSerializer#handledType}
  3. * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
  4. * sanity check).
  5. * For serializers that do not declare handled type, use the variant that takes
  6. * two arguments.
  7. *
  8. * @param ser
  9. */
  10. public void addSerializer(JsonSerializer<?> ser)
  11. {
  12. // Interface to match?
  13. Class<?> cls = ser.handledType();
  14. if (cls == null || cls == Object.class) {
  15. throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
  16. +" does not define valid handledType() -- must either register with method that takes type argument "
  17. +" or make serializer extend 'com.fasterxml.jackson.databind.ser.std.StdSerializer'");
  18. }
  19. _addSerializer(cls, ser);
  20. }

代码示例来源:origin: Nextdoor/bender

  1. throws IOException
  2. Class<?> clz = handledType();
  3. if (clz == null) {
  4. clz = value.getClass();

相关文章