Here are the examples of the java api class com.fasterxml.jackson.databind.annotation.JsonSerialize taken from open source projects.
1. MediaIT#shouldCreateByteArrayFieldWithAnyEncoding()
Project: jsonschema2pojo
File: MediaIT.java
File: MediaIT.java
@Test public void shouldCreateByteArrayFieldWithAnyEncoding() throws SecurityException, NoSuchFieldException { Field field = classWithMediaProperties.getDeclaredField("anyBinaryEncoding"); JsonSerialize serAnnotation = field.getAnnotation(JsonSerialize.class); JsonDeserialize deserAnnotation = field.getAnnotation(JsonDeserialize.class); assertThat("any binary encoding field has type byte[]", field.getType(), equalToType(BYTE_ARRAY)); assertThat("any binary encoding has a serializer", serAnnotation, notNullValue()); assertThat("any binary encoding has a deserializer", deserAnnotation, notNullValue()); }
2. JacksonUtil#findAdapterType()
Project: enunciate
File: JacksonUtil.java
File: JacksonUtil.java
private static AdapterType findAdapterType(DecoratedTypeMirror maybeContainedAdaptedType, Element referer, EnunciateJacksonContext context) { DecoratedProcessingEnvironment env = context.getContext().getProcessingEnvironment(); TypeMirror adaptedType = TypeMirrorUtils.getComponentType(maybeContainedAdaptedType, env); final boolean isContained = adaptedType != null; adaptedType = isContained ? adaptedType : maybeContainedAdaptedType; JsonSerialize serializationInfo = referer != null ? referer.getAnnotation(JsonSerialize.class) : null; if (serializationInfo == null && adaptedType instanceof DeclaredType) { serializationInfo = ((DeclaredType) adaptedType).asElement().getAnnotation(JsonSerialize.class); } if (serializationInfo != null) { final JsonSerialize finalInfo = serializationInfo; DecoratedTypeMirror adapterTypeMirror = Annotations.mirrorOf(new Callable<Class<?>>() { @Override public Class<?> call() throws Exception { return isContained ? finalInfo.contentConverter() : finalInfo.converter(); } }, env, Converter.None.class); if (adapterTypeMirror instanceof DeclaredType) { AdapterType adapterType = new AdapterType((DeclaredType) adapterTypeMirror, context); if ((adaptedType instanceof DeclaredType && adapterType.canAdapt(adaptedType, context.getContext())) || (maybeContainedAdaptedType != adaptedType && adapterType.canAdapt(maybeContainedAdaptedType, context.getContext()))) { return adapterType; } throw new EnunciateException(referer + ": adapter " + adapterTypeMirror + " does not adapt " + maybeContainedAdaptedType); } } if (context.isHonorJaxb()) { XmlJavaTypeAdapter typeAdapterInfo = referer != null ? referer.getAnnotation(XmlJavaTypeAdapter.class) : null; if (adaptedType instanceof DeclaredType) { if (typeAdapterInfo == null) { typeAdapterInfo = ((DeclaredType) adaptedType).asElement().getAnnotation(XmlJavaTypeAdapter.class); } } if (typeAdapterInfo != null) { final XmlJavaTypeAdapter finalInfo = typeAdapterInfo; DecoratedDeclaredType adapterTypeMirror = (DecoratedDeclaredType) Annotations.mirrorOf(new Callable<Class<?>>() { @Override public Class<?> call() throws Exception { return finalInfo.value(); } }, env); AdapterType adapterType = new AdapterType(adapterTypeMirror, context); if ((adaptedType instanceof DeclaredType && adapterType.canAdapt(adaptedType, context.getContext())) || (maybeContainedAdaptedType != adaptedType && adapterType.canAdapt(maybeContainedAdaptedType, context.getContext()))) { return adapterType; } throw new EnunciateException(referer + ": adapter " + adapterTypeMirror + " does not adapt " + maybeContainedAdaptedType); } } return null; }