Skip to content

Commit 61bf64a

Browse files
authored
Locale.ENGLISH should set. (#951)
1 parent 85d642b commit 61bf64a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/resources/jsv-messages_en.properties

Whitespace-only changes.

src/test/java/com/networknt/schema/LocaleTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import com.fasterxml.jackson.databind.JsonMappingException;
2727
import com.fasterxml.jackson.databind.JsonNode;
2828
import com.fasterxml.jackson.databind.ObjectMapper;
29+
import com.networknt.schema.SpecVersion.VersionFlag;
2930
import com.networknt.schema.i18n.Locales;
31+
import com.networknt.schema.serialization.JsonMapperFactory;
3032

3133
public class LocaleTest {
3234
private JsonSchema getSchema(SchemaValidatorsConfig config) {
@@ -65,4 +67,41 @@ void executionContextLocale() throws JsonMappingException, JsonProcessingExcepti
6567
assertEquals(1, messages.size());
6668
assertEquals("$.foo: integer trovato, string atteso", messages.iterator().next().getMessage());
6769
}
70+
71+
/**
72+
* Issue 949.
73+
* <p>
74+
* Locale.ENGLISH should work despite Locale.getDefault setting.
75+
*
76+
* @throws JsonMappingException the exception
77+
* @throws JsonProcessingException the exception
78+
*/
79+
@Test
80+
void englishLocale() throws JsonMappingException, JsonProcessingException {
81+
Locale locale = Locale.getDefault();
82+
try {
83+
Locale.setDefault(Locale.GERMAN);
84+
String schema = "{\r\n"
85+
+ " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\r\n"
86+
+ " \"$id\": \"https://www.example.com\",\r\n"
87+
+ " \"type\": \"object\"\r\n"
88+
+ "}";
89+
JsonSchema jsonSchema = JsonSchemaFactory.getInstance(VersionFlag.V7)
90+
.getSchema(JsonMapperFactory.getInstance().readTree(schema));
91+
String input = "1";
92+
Set<ValidationMessage> messages = jsonSchema.validate(input, InputFormat.JSON);
93+
assertEquals(1, messages.size());
94+
assertEquals("$: integer wurde gefunden, aber object erwartet", messages.iterator().next().toString());
95+
96+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
97+
config.setLocale(Locale.ENGLISH);
98+
jsonSchema = JsonSchemaFactory.getInstance(VersionFlag.V7)
99+
.getSchema(JsonMapperFactory.getInstance().readTree(schema), config);
100+
messages = jsonSchema.validate(input, InputFormat.JSON);
101+
assertEquals(1, messages.size());
102+
assertEquals("$: integer found, object expected", messages.iterator().next().toString());
103+
} finally {
104+
Locale.setDefault(locale);
105+
}
106+
}
68107
}

0 commit comments

Comments
 (0)