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
ondrej-hrstka committed Apr 20, 2022
1 parent cc1b245 commit 5317c88
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Expand Up @@ -257,6 +257,17 @@ public int getTextOffset() throws IOException {

@Override
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException {
JsonNode currentNode = currentNodeOrNull();

if (currentNode != null && currentNode.isNull()) {
return null;
}

String text = getText();
if (text != null) {
return b64variant.decode(text);
}

return null;
}

Expand Down
@@ -0,0 +1,27 @@
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 parser = new JsonNodeTraversingParser(jsonNode)

parser.nextToken()

def binaryValue = parser.getBinaryValue(Base64Variants.MIME)

expect:
binaryValue == expected?.bytes

where:
jsonNode || expected
JsonNode.createStringNode("YWJj") || "abc"
JsonNode.nullNode() || null
}

}

0 comments on commit 5317c88

Please sign in to comment.