Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed support for deserialization from Base64 into a byte array. (#7223) #7236

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}

}