Skip to content

Commit

Permalink
Fixed support for deserialization from Base64 into a byte array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Hrstka committed Apr 20, 2022
1 parent cc1b245 commit 6dea603
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Expand Up @@ -257,6 +257,10 @@ public int getTextOffset() throws IOException {

@Override
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException {
String text = getText();
if (text != null) {
return b64variant.decode(text);
}
return null;
}

Expand Down
@@ -0,0 +1,28 @@
package io.micronaut.jackson.core.tree

import com.fasterxml.jackson.core.Base64Variant
import com.fasterxml.jackson.core.Base64Variants
import io.micronaut.json.tree.JsonNode
import spock.lang.Specification

class JsonNodeTraversingParserTest extends Specification {

def getBinaryValue() {
given:
def jsonNode = JsonNode.createArrayNode([JsonNode.createStringNode(content)])
def parser = new JsonNodeTraversingParser(jsonNode)

parser.nextToken()
parser.nextToken()

def binaryValue = parser.getBinaryValue(Base64Variants.MIME)

expect:
new String(binaryValue) == expected

where:
content || expected
"YWJj" || "abc"
}

}

0 comments on commit 6dea603

Please sign in to comment.