Skip to content

Commit 040850a

Browse files
committed
Replace asText
1 parent 054d856 commit 040850a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/java/com/saasquatch/jsonschemainferrer/JunkDrawer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ static int getSerializedTextLength(@Nonnull JsonNode jsonNode) {
211211
return getBase64Length(binaryValue.length);
212212
} else if (isTextualFloat(jsonNode)) {
213213
// Handle NaN and infinity
214-
return jsonNode.asText().length();
214+
return jsonNode.asString().length();
215215
}
216-
final String textValue = jsonNode.textValue();
217-
if (textValue == null) {
216+
if (!jsonNode.isString()) {
218217
return -1;
219218
}
219+
final String textValue = jsonNode.stringValue();
220220
// DO NOT use String.length()
221221
return textValue.codePointCount(0, textValue.length());
222222
}

src/test/java/com/saasquatch/jsonschemainferrer/JsonSchemaInferrerOptionsTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ public void testEnum() {
610610
final JsonNode anyOf = schema.get("anyOf");
611611
assertTrue(anyOf.isArray());
612612
assertTrue(
613-
stream(anyOf).anyMatch(_anyOf -> _anyOf.path("enum").get(0).stringValue().equals("MARCH")));
613+
stream(anyOf).anyMatch(
614+
_anyOf -> _anyOf.path("enum").get(0).stringValue().equals("MARCH")));
614615
assertTrue(stream(anyOf)
615616
.anyMatch(_anyOf -> _anyOf.path("enum").get(0).stringValue().equals("TUESDAY")));
616617
}
@@ -699,8 +700,8 @@ public void testStringLengthFeatures() {
699700
.setStringLengthFeatures(EnumSet.allOf(StringLengthFeature.class))
700701
.build();
701702
final ObjectNode schema = inferrer.inferForSample(shouldBeText);
702-
assertEquals(shouldBeText.asText().length(), schema.path("minLength").intValue());
703-
assertEquals(shouldBeText.asText().length(), schema.path("maxLength").intValue());
703+
assertEquals(shouldBeText.asString().length(), schema.path("minLength").intValue());
704+
assertEquals(shouldBeText.asString().length(), schema.path("maxLength").intValue());
704705
}
705706
}
706707

0 commit comments

Comments
 (0)