Permalink
Browse files

Implemented [Issue-22], add ObjectMapper.setAnnotationIntrospectors(...)

  • Loading branch information...
1 parent 97b73c6 commit 752b57e524d5f85f2c2a6b7e97eddf9b5498794a @cowtowncoder cowtowncoder committed Jun 9, 2012
View
@@ -14,6 +14,8 @@ Improvements:
UntypedObjectDeserializer, even with default typing enabled.
* [Issue-9]: Implement 'required' JSON Schema attribute for bean properties
* [Issue-19]: Change OSGi bundle name to be fully-qualified
+* [Issue-22]: Add 'ObjectMapper.setAnnotationIntrospectors()' which allows
+ defining different introspectors for serialization, deserialization
------------------------------------------------------------------------
=== History: ===
@@ -619,9 +619,10 @@ public void addDeserializationProblemHandler(DeserializationProblemHandler handl
/**
* Method that returns the shared default {@link SerializationConfig}
* object that defines configuration settings for serialization.
- * Returned object is "live" meaning that changes will be used
- * for future serialization operations for this mapper when using
- * mapper's default configuration
+ *<p>
+ * Note that since instances are immutable, you can NOT change settings
+ * by accessing an instance and calling methods: this will simply create
+ * new instance of config object.
*/
public SerializationConfig getSerializationConfig() {
return _serializationConfig;
@@ -631,9 +632,10 @@ public SerializationConfig getSerializationConfig() {
* Method that returns
* the shared default {@link DeserializationConfig} object
* that defines configuration settings for deserialization.
- * Returned object is "live" meaning that changes will be used
- * for future deserialization operations for this mapper when using
- * mapper's default configuration
+ *<p>
+ * Note that since instances are immutable, you can NOT change settings
+ * by accessing an instance and calling methods: this will simply create
+ * new instance of config object.
*/
public DeserializationConfig getDeserializationConfig() {
return _deserializationConfig;
@@ -802,6 +804,26 @@ public ObjectMapper setAnnotationIntrospector(AnnotationIntrospector ai) {
_deserializationConfig = _deserializationConfig.with(ai);
return this;
}
+
+ /**
+ * Method for changing {@link AnnotationIntrospector} instances used
+ * by this mapper instance for serialization and deserialization,
+ * specifying them separately so that different introspection can be
+ * used for different aspects
+ *
+ * @since 2.1
+ *
+ * @param serializerAI {@link AnnotationIntrospector} to use for configuring
+ * serialization
+ * @param deserializerAI {@link AnnotationIntrospector} to use for configuring
+ * deserialization
+ */
+ public ObjectMapper setAnnotationIntrospectors(AnnotationIntrospector serializerAI,
+ AnnotationIntrospector deserializerAI) {
+ _serializationConfig = _serializationConfig.with(serializerAI);
+ _deserializationConfig = _deserializationConfig.with(deserializerAI);
+ return this;
+ }
/**
* Method for setting custom property naming strategy to use.
@@ -162,6 +162,17 @@ public SerializerFactory withConfig(SerializerFactoryConfig config)
if (origType.isContainerType()) {
if (!staticTyping) {
staticTyping = usesStaticTyping(config, beanDesc, null, property);
+
+ // [JACKSON-822]: Need to figure out how to force passed parameterization
+ // to stick...
+ /*
+ if (property == null) {
+ JavaType t = origType.getContentType();
+ if (t != null && !t.hasRawClass(Object.class)) {
+ staticTyping = true;
+ }
+ }
+ */
}
return (JsonSerializer<Object>) buildContainerSerializer(prov,
type, beanDesc, property, staticTyping);
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.databind.util;
import java.io.IOException;
+import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -636,6 +637,17 @@ public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int l
writeObject(copy);
}
+ /**
+ * Although we could support this method, it does not necessarily make
+ * sense: we can not make good use of streaming because buffer must
+ * hold all the data. Because of this, currently this will simply
+ * throw {@link UnsupportedOperationException}
+ */
+ @Override
+ public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) {
+ throw new UnsupportedOperationException();
+ }
+
/*
/**********************************************************
/* JsonGenerator implementation; pass-through copy
@@ -203,30 +203,20 @@ public void writeString(char[] text, int offset, int len) { }
public void writeUTF8String(byte[] text, int offset, int length) { }
@Override
- public void writeStartArray() throws IOException,
- JsonGenerationException {
- // TODO Auto-generated method stub
-
- }
+ public void writeStartArray() { }
@Override
- public void writeEndArray() throws IOException, JsonGenerationException {
- // TODO Auto-generated method stub
-
- }
+ public void writeEndArray() throws IOException, JsonGenerationException { }
@Override
- public void writeStartObject() throws IOException,
- JsonGenerationException {
- // TODO Auto-generated method stub
-
- }
+ public void writeStartObject() { }
+
+ @Override
+ public void writeEndObject() { }
@Override
- public void writeEndObject() throws IOException,
- JsonGenerationException {
- // TODO Auto-generated method stub
-
+ public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) {
+ return -1;
}
}

0 comments on commit 752b57e

Please sign in to comment.