Skip to content

Commit

Permalink
Implemented #1, allowing JsonParser as input to bind to
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 17, 2013
1 parent 3892c78 commit 8dc0de7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Expand Up @@ -432,6 +432,7 @@ public void writeTo(Object value, Class<?> type, Type genericType, Annotation[]
}
}
}

// Most of the configuration now handled through EndpointConfig, ObjectWriter
// but we may need to force root type:
if (rootType != null) {
Expand Down Expand Up @@ -494,6 +495,9 @@ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotati
}
// Finally: if we really want to verify that we can serialize, we'll check:
if (_cfgCheckCanSerialize) {
if (_isSpecialReadable(type)) {
return true;
}
ObjectMapper mapper = locateMapper(type, mediaType);
if (!mapper.canDeserialize(mapper.constructType(type))) {
return false;
Expand Down Expand Up @@ -529,6 +533,10 @@ public Object readFrom(Class<Object> type, Type genericType, Annotation[] annota
if (jp == null || jp.nextToken() == null) {
return null;
}
// [Issue#1]: allow 'binding' to JsonParser
if (((Class<?>) type) == JsonParser.class) {
return jp;
}
return reader.withType(genericType).readValue(jp);
}

Expand All @@ -543,13 +551,13 @@ protected JsonParser _createParser(ObjectReader reader, InputStream rawStream)
{
return reader.getFactory().createParser(rawStream);
}

/*
/**********************************************************
/* Private/sub-class helper methods
/* Overridable helper methods
/**********************************************************
*/

/**
* Method called to locate {@link ObjectMapper} to use for serialization
* and deserialization. If an instance has been explicitly defined by
Expand Down Expand Up @@ -585,6 +593,22 @@ public MAPPER locateMapper(Class<?> type, MediaType mediaType)
return m;
}

/**
* Overridable helper method used to allow handling of somewhat special
* types for reading
*
* @since 2.2
*/
protected boolean _isSpecialReadable(Class<?> type) {
return JsonParser.class == type;
}

/*
/**********************************************************
/* Private/sub-class helper methods
/**********************************************************
*/

protected static boolean _containedIn(Class<?> mainType, HashSet<ClassKey> set)
{
if (set != null) {
Expand Down
1 change: 1 addition & 0 deletions release-notes/VERSION
Expand Up @@ -9,6 +9,7 @@ First multi-module release, to make release easier, share some boilerplate code.

Changes:

#1: Allow binding input to `JsonParser`
#5: Add 'provider.removeUntouchable()'
* Add Woodstox dependency (not just in 'test' scope) to try to avoid problems
with users relying on SJSXP (such as 'extra' xmlns declarations)
Expand Down

0 comments on commit 8dc0de7

Please sign in to comment.