Skip to content

Commit

Permalink
Fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 27, 2014
1 parent 314e2a3 commit 6b75ae8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<version>2.4.5-SNAPSHOT</version>
<packaging>bundle</packaging>
<description>Add-on module for Jackson (http://jackson.codehaus.org) to support
working with JSR-353 (JDK Json-processing API) node typesm via data-binding
working with JSR-353 (JDK Json-processing API) node types via data-binding
</description>
<url>https://github.com/FasterXML/jackson</url>
<scm>
Expand All @@ -22,7 +22,7 @@ working with JSR-353 (JDK Json-processing API) node typesm via data-binding
<tag>HEAD</tag>
</scm>
<properties>
<version.jackson.core>2.4.4</version.jackson.core>
<version.jackson.core>2.4.5-SNAPSHOT</version.jackson.core>

<!-- Configuration properties for the OSGi maven-bundle-plugin -->
<osgi.import>com.fasterxml.jackson.core
Expand Down
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-datatype-jsr353
=== Releases ===
------------------------------------------------------------------------

2.4.5 (not released yet)

#5: Support conversion of `BinaryNode`, as base64-encoded text
(suggested by Gabor B, aborg0@github)

2.4.4 (24-Nov-2014)
2.4.3 (04-Oct-2014)
2.4.2 (15-Aug-2014)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonParser.NumberType;
import com.fasterxml.jackson.core.Base64Variants;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand Down Expand Up @@ -101,6 +102,17 @@ protected JsonValue _deserializeObject(JsonParser jp, DeserializationContext ctx
case VALUE_STRING:
b.add(name, jp.getText());
break;
case VALUE_EMBEDDED_OBJECT:
{
// 26-Nov-2014, tatu: As per [issue#5], should be able to support
// binary data as Base64 embedded text
Object ob = jp.getEmbeddedObject();
if (ob instanceof byte[]) {
String b64 = ctxt.getBase64Variant().encode((byte[]) ob, false);
b.add(name, b64);
break;
}
}
default:
throw ctxt.mappingException(JsonValue.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.fasterxml.jackson.datatype.jsr353;

import javax.json.*;
import javax.json.JsonValue.ValueType;

import com.fasterxml.jackson.databind.node.ObjectNode;

public class SimpleDeserializeTest extends TestBase
{
Expand Down Expand Up @@ -79,4 +82,19 @@ public void testNestedObject() throws Exception
// and round-tripping ought to be ok:
assertEquals(JSON, serializeAsString(v));
}

// for [issue#5]
public void testBinaryNode() throws Exception
{
ObjectNode root = MAPPER.createObjectNode();
root.put("b", new byte[1]);
JsonValue v = MAPPER.convertValue(root, JsonValue.class);
assertNotNull(v);
assertEquals(ValueType.OBJECT, v.getValueType());
JsonValue v2 = ((javax.json.JsonObject) v).get("b");
assertNotNull(v2);
assertEquals(ValueType.STRING, v2.getValueType());
String str = ((JsonString) v2).getString();
assertEquals("AA==", str); // single zero byte
}
}

0 comments on commit 6b75ae8

Please sign in to comment.