@@ -17,6 +17,13 @@ public class Jtd {
1717
1818 private static final Logger LOG = Logger .getLogger (Jtd .class .getName ());
1919
20+ /// RFC 8927 §2.2.3: Valid primitive types for type schema validation
21+ private static final Set <String > VALID_TYPES = Set .of (
22+ "boolean" , "string" , "timestamp" ,
23+ "int8" , "uint8" , "int16" , "uint16" , "int32" , "uint32" ,
24+ "float32" , "float64"
25+ );
26+
2027 /// Top-level definitions map for ref resolution
2128 private final Map <String , JtdSchema > definitions = new java .util .HashMap <>();
2229
@@ -497,13 +504,7 @@ JtdSchema compileTypeSchema(JsonObject obj) {
497504 String typeStr = str .value ();
498505
499506 // RFC 8927 §2.2.3: Validate that type is one of the supported primitive types
500- Set <String > validTypes = Set .of (
501- "boolean" , "string" , "timestamp" ,
502- "int8" , "uint8" , "int16" , "uint16" , "int32" , "uint32" ,
503- "float32" , "float64"
504- );
505-
506- if (!validTypes .contains (typeStr )) {
507+ if (!VALID_TYPES .contains (typeStr )) {
507508 throw new IllegalArgumentException ("unknown type: '" + typeStr +
508509 "', expected one of: boolean, string, timestamp, int8, uint8, int16, uint16, int32, uint32, float32, float64" );
509510 }
@@ -662,16 +663,16 @@ JtdSchema compileDiscriminatorSchema(JsonObject obj, boolean isRoot) {
662663 void validateDiscriminatorMapping (String mappingKey , JtdSchema variantSchema , String discriminatorKey ) {
663664 // Check if this is a nullable schema and unwrap it
664665 JtdSchema unwrappedSchema = variantSchema ;
665- boolean isNullable = false ;
666+ boolean wasNullableWrapper = false ;
666667
667668 if (variantSchema instanceof JtdSchema .NullableSchema nullableSchema ) {
668- isNullable = true ;
669+ wasNullableWrapper = true ;
669670 unwrappedSchema = nullableSchema .wrapped ();
670671 }
671672
672673 // RFC 8927 §2.2.8: Mapping values must be PropertiesSchema
673674 if (!(unwrappedSchema instanceof JtdSchema .PropertiesSchema )) {
674- String schemaType = isNullable ? "nullable " + unwrappedSchema .getClass ().getSimpleName () :
675+ String schemaType = wasNullableWrapper ? "nullable " + unwrappedSchema .getClass ().getSimpleName () :
675676 unwrappedSchema .getClass ().getSimpleName ();
676677 throw new IllegalArgumentException (
677678 "Discriminator mapping '" + mappingKey + "' must be a properties schema, found: " + schemaType );
@@ -680,7 +681,7 @@ void validateDiscriminatorMapping(String mappingKey, JtdSchema variantSchema, St
680681 JtdSchema .PropertiesSchema propsSchema = (JtdSchema .PropertiesSchema ) unwrappedSchema ;
681682
682683 // RFC 8927 §2.2.8: Mapped schemas cannot have nullable: true
683- if (isNullable ) {
684+ if (wasNullableWrapper ) {
684685 throw new IllegalArgumentException (
685686 "Discriminator mapping '" + mappingKey + "' cannot be nullable" );
686687 }
0 commit comments