Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.0.76</version>
<version>1.0.77</version>
<packaging>bundle</packaging>
<description>A json schema validator that supports draft v4, v6, v7, v2019-09 and v2020-12</description>
<url>https://github.com/networknt/json-schema-validator</url>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/networknt/schema/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public static JsonType getValueNodeType(JsonNode node, SchemaValidatorsConfig co
if (node.isValueNode()) {
if (node.isTextual())
return JsonType.STRING;
if (node.isBinary())
return JsonType.STRING;
if (node.isIntegralNumber())
return JsonType.INTEGER;
if (node.isNumber())
Expand Down
84 changes: 84 additions & 0 deletions src/test/java/com/networknt/schema/Issue650Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.networknt.schema;

import static org.junit.jupiter.api.Assertions.*;
import java.io.InputStream;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.BinaryNode;

/**
*
* created at 07.02.2023
*
* @author k-oliver
* @since 1.0.77
*/
public class Issue650Test {

/**
* Test using a Java model with a byte[] property which jackson converts to a BASE64 encoded string automatically. Then convert into
* a jackson tree. The resulting node is of type {@link BinaryNode}. This test checks if validation handles the {@link BinaryNode} as string
* when validating.
*
* @throws Exception
* @since 1.0.77
*/
@Test
public void testBinaryNode() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

// schema with data property of type string:
InputStream schemaInputStream = getClass().getResourceAsStream("/draft7/issue650.json");
JsonSchema schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7).getSchema(schemaInputStream);

// create model first:
Issue650Test.Model model = new Issue650Test.Model();
model.setData("content".getBytes("UTF-8"));
// now convert to tree. The resulting type of the data property is BinaryNode now:
JsonNode node = mapper.valueToTree(model);

// validate:
Set<ValidationMessage> errors = schema.validate(node);

// check result:
Assertions.assertTrue(errors.isEmpty());
}

/**
* created at 07.02.2023
*
* @author Oliver Kelling
* @since 1.0.77
*/
private static class Model {
private byte[] data;


/**
* @return the data
* @since 1.0.77
*/
public byte[] getData() {
return this.data;
}


/**
* @param data the data to set
* @since 1.0.77
*/
public void setData(byte[] data) {
this.data = data;
}

}
}
13 changes: 13 additions & 0 deletions src/test/resources/draft7/issue650.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"$id": "#/properties/data",
"type": "string"
}
}
}