structurize 2.18.1__tar.gz → 2.18.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. {structurize-2.18.1/structurize.egg-info → structurize-2.18.2}/PKG-INFO +1 -1
  2. {structurize-2.18.1 → structurize-2.18.2}/avrotize/_version.py +3 -3
  3. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotojava.py +74 -30
  4. {structurize-2.18.1 → structurize-2.18.2/structurize.egg-info}/PKG-INFO +1 -1
  5. {structurize-2.18.1 → structurize-2.18.2}/.gitignore +0 -0
  6. {structurize-2.18.1 → structurize-2.18.2}/LICENSE +0 -0
  7. {structurize-2.18.1 → structurize-2.18.2}/MANIFEST.in +0 -0
  8. {structurize-2.18.1 → structurize-2.18.2}/README.md +0 -0
  9. {structurize-2.18.1 → structurize-2.18.2}/avrotize/__init__.py +0 -0
  10. {structurize-2.18.1 → structurize-2.18.2}/avrotize/__main__.py +0 -0
  11. {structurize-2.18.1 → structurize-2.18.2}/avrotize/asn1toavro.py +0 -0
  12. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotize.py +0 -0
  13. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotocpp.py +0 -0
  14. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotocsharp.py +0 -0
  15. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotocsv.py +0 -0
  16. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotodatapackage.py +0 -0
  17. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotodb.py +0 -0
  18. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotogo.py +0 -0
  19. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotographql.py +0 -0
  20. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotoiceberg.py +0 -0
  21. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotojs.py +0 -0
  22. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotojsons.py +0 -0
  23. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotojstruct.py +0 -0
  24. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotokusto.py +0 -0
  25. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotomd.py +0 -0
  26. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotools.py +0 -0
  27. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotoparquet.py +0 -0
  28. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotoproto.py +0 -0
  29. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotopython.py +0 -0
  30. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotorust.py +0 -0
  31. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotots.py +0 -0
  32. {structurize-2.18.1 → structurize-2.18.2}/avrotize/avrotoxsd.py +0 -0
  33. {structurize-2.18.1 → structurize-2.18.2}/avrotize/commands.json +0 -0
  34. {structurize-2.18.1 → structurize-2.18.2}/avrotize/common.py +0 -0
  35. {structurize-2.18.1 → structurize-2.18.2}/avrotize/constants.py +0 -0
  36. {structurize-2.18.1 → structurize-2.18.2}/avrotize/csvtoavro.py +0 -0
  37. {structurize-2.18.1 → structurize-2.18.2}/avrotize/datapackagetoavro.py +0 -0
  38. {structurize-2.18.1 → structurize-2.18.2}/avrotize/dependency_resolver.py +0 -0
  39. {structurize-2.18.1 → structurize-2.18.2}/avrotize/jsonstoavro.py +0 -0
  40. {structurize-2.18.1 → structurize-2.18.2}/avrotize/jsonstostructure.py +0 -0
  41. {structurize-2.18.1 → structurize-2.18.2}/avrotize/jstructtoavro.py +0 -0
  42. {structurize-2.18.1 → structurize-2.18.2}/avrotize/kstructtoavro.py +0 -0
  43. {structurize-2.18.1 → structurize-2.18.2}/avrotize/kustotoavro.py +0 -0
  44. {structurize-2.18.1 → structurize-2.18.2}/avrotize/parquettoavro.py +0 -0
  45. {structurize-2.18.1 → structurize-2.18.2}/avrotize/proto2parser.py +0 -0
  46. {structurize-2.18.1 → structurize-2.18.2}/avrotize/proto3parser.py +0 -0
  47. {structurize-2.18.1 → structurize-2.18.2}/avrotize/prototoavro.py +0 -0
  48. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretocpp.py +0 -0
  49. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretocsharp.py +0 -0
  50. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretocsv.py +0 -0
  51. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretodatapackage.py +0 -0
  52. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretodb.py +0 -0
  53. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretogo.py +0 -0
  54. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretographql.py +0 -0
  55. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretoiceberg.py +0 -0
  56. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretojsons.py +0 -0
  57. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretokusto.py +0 -0
  58. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretomd.py +0 -0
  59. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretoproto.py +0 -0
  60. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretopython.py +0 -0
  61. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretorust.py +0 -0
  62. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretots.py +0 -0
  63. {structurize-2.18.1 → structurize-2.18.2}/avrotize/structuretoxsd.py +0 -0
  64. {structurize-2.18.1 → structurize-2.18.2}/avrotize/xsdtoavro.py +0 -0
  65. {structurize-2.18.1 → structurize-2.18.2}/build.ps1 +0 -0
  66. {structurize-2.18.1 → structurize-2.18.2}/build.sh +0 -0
  67. {structurize-2.18.1 → structurize-2.18.2}/pyproject.toml +0 -0
  68. {structurize-2.18.1 → structurize-2.18.2}/setup.cfg +0 -0
  69. {structurize-2.18.1 → structurize-2.18.2}/structurize.egg-info/SOURCES.txt +0 -0
  70. {structurize-2.18.1 → structurize-2.18.2}/structurize.egg-info/dependency_links.txt +0 -0
  71. {structurize-2.18.1 → structurize-2.18.2}/structurize.egg-info/entry_points.txt +0 -0
  72. {structurize-2.18.1 → structurize-2.18.2}/structurize.egg-info/requires.txt +0 -0
  73. {structurize-2.18.1 → structurize-2.18.2}/structurize.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structurize
3
- Version: 2.18.1
3
+ Version: 2.18.2
4
4
  Summary: Tools to convert from and to JSON Structure from various other schema languages.
5
5
  Author-email: Clemens Vasters <clemensv@microsoft.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.18.1'
32
- __version_tuple__ = version_tuple = (2, 18, 1)
31
+ __version__ = version = '2.18.2'
32
+ __version_tuple__ = version_tuple = (2, 18, 2)
33
33
 
34
- __commit_id__ = commit_id = 'gdae473138'
34
+ __commit_id__ = commit_id = 'g857734aaf'
@@ -693,7 +693,8 @@ class AvroToJava:
693
693
  elif items_type in self.generated_types_java_package:
694
694
  kind = self.generated_types_java_package[items_type]
695
695
  if kind == "enum":
696
- pred += f"n.elements().next().isTextual() && Enum.valueOf({items_type}.class, n.elements().next().asText()) != null"
696
+ # Try to match the incoming text against Avro symbols
697
+ pred += f"n.elements().next().isTextual() && java.util.Arrays.stream({items_type}.values()).anyMatch(e -> e.avroSymbol().equals(n.elements().next().asText()))"
697
698
  else:
698
699
  pred += f"{items_type}.isJsonMatch(n.elements().next())"
699
700
  else:
@@ -710,7 +711,8 @@ class AvroToJava:
710
711
  elif values_type in self.generated_types_java_package:
711
712
  kind = self.generated_types_java_package[values_type]
712
713
  if kind == "enum":
713
- pred += f"n.elements().next().isTextual() && Enum.valueOf({values_type}.class, n.elements().next().asText()) != null"
714
+ # Try to match the incoming text against Avro symbols
715
+ pred += f"n.elements().next().isTextual() && java.util.Arrays.stream({values_type}.values()).anyMatch(e -> e.avroSymbol().equals(n.elements().next().asText()))"
714
716
  else:
715
717
  pred += f"{values_type}.isJsonMatch(n.elements().next())"
716
718
  else:
@@ -730,7 +732,8 @@ class AvroToJava:
730
732
  raw_const = const_value if isinstance(const_value, str) else str(const_value)
731
733
  class_definition += f"(node.has(\"{field_name_js}\") && node.get(\"{field_name_js}\").isTextual() && node.get(\"{field_name_js}\").asText().equals(\"{raw_const}\"))"
732
734
  else:
733
- class_definition += f"(node.get(\"{field_name_js}\").isTextual() && Enum.valueOf({field_type.type_name}.class, node.get(\"{field_name_js}\").asText()) != null)"
735
+ # Try to match the incoming text against Avro symbols
736
+ class_definition += f"(node.get(\"{field_name_js}\").isTextual() && java.util.Arrays.stream({field_type.type_name}.values()).anyMatch(e -> e.avroSymbol().equals(node.get(\"{field_name_js}\").asText())))"
734
737
  else:
735
738
  is_union = False
736
739
  field_union = pascal(field_name) + 'Union'
@@ -802,7 +805,8 @@ class AvroToJava:
802
805
  elif field_type.is_class:
803
806
  class_definition += f"({null_check} || {field_type.type_name}.isJsonMatch({element_name}))"
804
807
  elif field_type.is_enum:
805
- class_definition += f"({null_check} || ({node_check}.isTextual() && Enum.valueOf({field_type.type_name}.class, {element_name}.asText()) != null))"
808
+ # Try to match the incoming text against Avro symbols
809
+ class_definition += f"({null_check} || ({node_check}.isTextual() && java.util.Arrays.stream({field_type.type_name}.values()).anyMatch(e -> e.avroSymbol().equals({element_name}.asText()))))"
806
810
  else:
807
811
  is_union = False
808
812
  field_union = pascal(element_name) + 'Union'
@@ -1022,8 +1026,8 @@ class AvroToJava:
1022
1026
  get_method += f"{INDENT * 3}case {index}: return this.{field_name} != null ? this.{field_name}.entrySet().stream().collect(java.util.stream.Collectors.toMap(java.util.Map.Entry::getKey, e -> e.getValue() != null ? e.getValue().toObject() : null)) : null;\n"
1023
1027
  elif field_type.is_enum:
1024
1028
  # For enum fields, convert to GenericEnumSymbol for Avro serialization
1025
- # This allows SpecificDatumWriter to serialize enums inside unions correctly
1026
- get_method += f"{INDENT * 3}case {index}: return this.{field_name} != null ? new GenericData.EnumSymbol({field_type.type_name}.SCHEMA, this.{field_name}.name()) : null;\n"
1029
+ # Use avroSymbol() to get the original Avro symbol name for serialization
1030
+ get_method += f"{INDENT * 3}case {index}: return this.{field_name} != null ? new GenericData.EnumSymbol({field_type.type_name}.SCHEMA, this.{field_name}.avroSymbol()) : null;\n"
1027
1031
  else:
1028
1032
  # For all other field types, return the field as-is
1029
1033
  # Avro's SpecificDatumWriter will handle serialization internally
@@ -1104,7 +1108,8 @@ class AvroToJava:
1104
1108
  put_method += f"{INDENT * 3}case {index}: this.{field_name} = value$ instanceof GenericData.Record ? new {field_type.type_name}((GenericData.Record)value$) : ({field_type.type_name})value$; break;\n"
1105
1109
  elif type_kind == "enum":
1106
1110
  # Enums need to be converted from GenericData.EnumSymbol
1107
- put_method += f"{INDENT * 3}case {index}: this.{field_name} = value$ instanceof GenericData.EnumSymbol ? {field_type.type_name}.valueOf(value$.toString()) : ({field_type.type_name})value$; break;\n"
1111
+ # Use fromAvroSymbol to match original Avro symbol names
1112
+ put_method += f"{INDENT * 3}case {index}: this.{field_name} = value$ instanceof GenericData.EnumSymbol ? {field_type.type_name}.fromAvroSymbol(value$.toString()) : ({field_type.type_name})value$; break;\n"
1108
1113
  else:
1109
1114
  # Check if this is a List<RecordType> or Map<String,RecordType>
1110
1115
  is_list_of_records = False
@@ -1164,10 +1169,11 @@ class AvroToJava:
1164
1169
  # Check if it's a List of enums
1165
1170
  if element_type in self.generated_types_java_package and self.generated_types_java_package[element_type] == "enum":
1166
1171
  # For List<Enum>, convert GenericEnumSymbol to actual enum values
1172
+ # Use fromAvroSymbol to match original Avro symbol names
1167
1173
  put_method += f"{INDENT * 3}case {index}: {{\n"
1168
1174
  put_method += f"{INDENT * 4}if (value$ instanceof List<?>) {{\n"
1169
1175
  put_method += f"{INDENT * 5}List<?> list = (List<?>)value$;\n"
1170
- put_method += f"{INDENT * 5}this.{field_name} = list.stream().map(item -> item instanceof GenericData.EnumSymbol ? {element_type}.valueOf(item.toString()) : ({element_type})item).collect(java.util.stream.Collectors.toList());\n"
1176
+ put_method += f"{INDENT * 5}this.{field_name} = list.stream().map(item -> item instanceof GenericData.EnumSymbol ? {element_type}.fromAvroSymbol(item.toString()) : ({element_type})item).collect(java.util.stream.Collectors.toList());\n"
1171
1177
  put_method += f"{INDENT * 4}}} else {{\n"
1172
1178
  put_method += f"{INDENT * 5}this.{field_name} = null;\n"
1173
1179
  put_method += f"{INDENT * 4}}}\n"
@@ -1211,20 +1217,44 @@ class AvroToJava:
1211
1217
  self.generated_types_java_package[type_name] = "enum"
1212
1218
  self.generated_avro_schemas[type_name] = avro_schema
1213
1219
  symbols = avro_schema.get('symbols', [])
1214
- # Convert symbols to valid Java identifiers, preserving case
1220
+ # Convert symbols to valid Java identifiers in SCREAMING_CASE (uppercase)
1215
1221
  # Replace invalid chars, prepend _ if starts with digit or is a reserved word
1222
+ # Keep track of mapping from Java symbol to original Avro symbol for serialization
1216
1223
  java_symbols = []
1224
+ symbol_pairs = [] # (java_symbol, avro_symbol) pairs
1217
1225
  for symbol in symbols:
1218
- java_symbol = symbol.replace('-', '_').replace('.', '_')
1226
+ java_symbol = symbol.replace('-', '_').replace('.', '_').upper()
1219
1227
  if java_symbol and java_symbol[0].isdigit():
1220
1228
  java_symbol = '_' + java_symbol
1221
1229
  # Check if the symbol is a Java reserved word and prefix with underscore
1222
- if is_java_reserved_word(java_symbol):
1230
+ if is_java_reserved_word(java_symbol.lower()):
1223
1231
  java_symbol = '_' + java_symbol
1224
1232
  java_symbols.append(java_symbol)
1225
- symbols_str = ', '.join(java_symbols)
1233
+ symbol_pairs.append((java_symbol, symbol))
1234
+
1235
+ # Build enum with avroSymbol field for proper Avro serialization
1226
1236
  enum_definition += f"public enum {enum_name} {{\n"
1227
- enum_definition += f"{INDENT}{symbols_str}"
1237
+ # Each enum constant has its original Avro symbol stored
1238
+ enum_constants = []
1239
+ for java_symbol, avro_symbol in symbol_pairs:
1240
+ enum_constants.append(f'{java_symbol}("{avro_symbol}")')
1241
+ enum_definition += f"{INDENT}" + ", ".join(enum_constants)
1242
+
1243
+ # Add avroSymbol field and method with Jackson annotations for proper JSON serialization
1244
+ enum_definition += f";\n\n{INDENT}private final String avroSymbol;\n\n"
1245
+ enum_definition += f"{INDENT}{enum_name}(String avroSymbol) {{\n{INDENT*2}this.avroSymbol = avroSymbol;\n{INDENT}}}\n\n"
1246
+ # @JsonValue tells Jackson to serialize the enum using avroSymbol() value
1247
+ enum_definition += f"{INDENT}@com.fasterxml.jackson.annotation.JsonValue\n"
1248
+ enum_definition += f"{INDENT}public String avroSymbol() {{\n{INDENT*2}return avroSymbol;\n{INDENT}}}\n\n"
1249
+
1250
+ # Add static lookup method to find enum by Avro symbol with @JsonCreator for deserialization
1251
+ enum_definition += f"{INDENT}@com.fasterxml.jackson.annotation.JsonCreator\n"
1252
+ enum_definition += f"{INDENT}public static {enum_name} fromAvroSymbol(String symbol) {{\n"
1253
+ enum_definition += f"{INDENT*2}for ({enum_name} e : values()) {{\n"
1254
+ enum_definition += f"{INDENT*3}if (e.avroSymbol.equals(symbol)) return e;\n"
1255
+ enum_definition += f"{INDENT*2}}}\n"
1256
+ enum_definition += f"{INDENT*2}throw new IllegalArgumentException(\"Unknown symbol: \" + symbol);\n"
1257
+ enum_definition += f"{INDENT}}}\n"
1228
1258
 
1229
1259
  # Add Avro schema if annotations are enabled
1230
1260
  if self.avro_annotation:
@@ -1245,9 +1275,7 @@ class AvroToJava:
1245
1275
  [enum_schema_json[i:i+80] for i in range(0, len(enum_schema_json), 80)])
1246
1276
  enum_schema_json = enum_schema_json.replace('§', '\\"')
1247
1277
 
1248
- enum_definition += f";\n\n{INDENT}public static final Schema SCHEMA = new Schema.Parser().parse(\n{INDENT}\"{enum_schema_json}\");\n"
1249
- else:
1250
- enum_definition += f";\n"
1278
+ enum_definition += f"\n{INDENT}public static final Schema SCHEMA = new Schema.Parser().parse(\n{INDENT}\"{enum_schema_json}\");\n"
1251
1279
 
1252
1280
  enum_definition += "}\n"
1253
1281
  if write_file:
@@ -1295,8 +1323,9 @@ class AvroToJava:
1295
1323
  f"{INDENT*1}public {union_type.type_name} get{union_variable_name}() {{ return _{camel(union_variable_name)}; }}\n";
1296
1324
 
1297
1325
  # For toObject(), wrap enums in GenericData.EnumSymbol so Avro can serialize them
1326
+ # Use avroSymbol() to get the original Avro symbol name for serialization
1298
1327
  if union_type.is_enum:
1299
- class_definition_toobject += f"{INDENT*2}if (_{camel(union_variable_name)} != null) {{\n{INDENT*3}return new GenericData.EnumSymbol({union_type.type_name}.SCHEMA, _{camel(union_variable_name)}.name());\n{INDENT*2}}}\n"
1328
+ class_definition_toobject += f"{INDENT*2}if (_{camel(union_variable_name)} != null) {{\n{INDENT*3}return new GenericData.EnumSymbol({union_type.type_name}.SCHEMA, _{camel(union_variable_name)}.avroSymbol());\n{INDENT*2}}}\n"
1300
1329
  else:
1301
1330
  class_definition_toobject += f"{INDENT*2}if (_{camel(union_variable_name)} != null) {{\n{INDENT*3}return _{camel(union_variable_name)};\n{INDENT*2}}}\n"
1302
1331
 
@@ -1326,8 +1355,9 @@ class AvroToJava:
1326
1355
  class_definition_fromobjectctor += f"{INDENT*2}if (obj instanceof org.apache.avro.util.Utf8) {{\n{INDENT*3}this._{camel(union_variable_name)} = obj.toString();\n{INDENT*3}return;\n{INDENT*2}}}\n"
1327
1356
 
1328
1357
  # Handle Avro's GenericEnumSymbol for enum types
1358
+ # Use fromAvroSymbol to match original Avro symbol names
1329
1359
  if self.avro_annotation and union_type.is_enum:
1330
- class_definition_fromobjectctor += f"{INDENT*2}if (obj instanceof GenericData.EnumSymbol) {{\n{INDENT*3}this._{camel(union_variable_name)} = {union_type.type_name}.valueOf(obj.toString());\n{INDENT*3}return;\n{INDENT*2}}}\n"
1360
+ class_definition_fromobjectctor += f"{INDENT*2}if (obj instanceof GenericData.EnumSymbol) {{\n{INDENT*3}this._{camel(union_variable_name)} = {union_type.type_name}.fromAvroSymbol(obj.toString());\n{INDENT*3}return;\n{INDENT*2}}}\n"
1331
1361
 
1332
1362
  class_definition_fromobjectctor += f"{INDENT*2}if (obj instanceof {union_type.type_name}) {{\n{INDENT*3}this._{camel(union_variable_name)} = ({union_type.type_name})obj;\n{INDENT*3}return;\n{INDENT*2}}}\n"
1333
1363
 
@@ -1356,7 +1386,8 @@ class AvroToJava:
1356
1386
  else:
1357
1387
  # For classes and enums, use duck typing with isJsonMatch() (C# pattern)
1358
1388
  if union_type.is_enum:
1359
- class_definition_read += f"{INDENT*3}if (node.isTextual()) {{\n{INDENT*4}return new {union_class_name}(Enum.valueOf({union_type.type_name}.class, node.asText()));\n{INDENT*3}}}\n"
1389
+ # Use fromAvroSymbol to match original Avro symbol names
1390
+ class_definition_read += f"{INDENT*3}if (node.isTextual()) {{\n{INDENT*4}return new {union_class_name}({union_type.type_name}.fromAvroSymbol(node.asText()));\n{INDENT*3}}}\n"
1360
1391
  elif union_type.is_class:
1361
1392
  # Use isJsonMatch() to test if this type matches, then use fromData() to deserialize
1362
1393
  class_definition_read += f"{INDENT*3}if ({union_type.type_name}.isJsonMatch(node)) {{\n{INDENT*4}return new {union_class_name}({union_type.type_name}.fromData(node, \"application/json\"));\n{INDENT*3}}}\n"
@@ -1449,9 +1480,15 @@ class AvroToJava:
1449
1480
  const_value = field['const']
1450
1481
  is_discriminator = field.get('discriminator', False)
1451
1482
 
1452
- # For enum types, qualify with the enum type name
1483
+ # For enum types, qualify with the enum type name and convert to SCREAMING_CASE
1453
1484
  if field_type.type_name not in ('String', 'int', 'Integer', 'long', 'Long', 'double', 'Double', 'boolean', 'Boolean'):
1454
- const_value = f'{field_type.type_name}.{const_value}'
1485
+ # Convert enum const value to uppercase to match Java enum constant naming convention
1486
+ const_value_upper = str(const_value).replace('-', '_').replace('.', '_').upper()
1487
+ if const_value_upper and const_value_upper[0].isdigit():
1488
+ const_value_upper = '_' + const_value_upper
1489
+ if is_java_reserved_word(const_value_upper.lower()):
1490
+ const_value_upper = '_' + const_value_upper
1491
+ const_value = f'{field_type.type_name}.{const_value_upper}'
1455
1492
  elif field_type.type_name == 'String':
1456
1493
  const_value = f'"{const_value}"'
1457
1494
 
@@ -1464,11 +1501,12 @@ class AvroToJava:
1464
1501
  property_def += f"{INDENT}@JsonIgnore\n"
1465
1502
  property_def += f"{INDENT}public {field_type.type_name} get{pascal(field_name)}Value() {{ return {safe_field_name}; }}\n"
1466
1503
  # Generate the getter that returns String (Jackson will use this for serialization)
1504
+ # Use avroSymbol() to get the original Avro symbol name for serialization
1467
1505
  # Use READ_ONLY since this is a const field that doesn't need deserialization
1468
1506
  # Note: Not using @Override because not all discriminated union variants extend a base class
1469
1507
  if self.jackson_annotations:
1470
1508
  property_def += f"{INDENT}@JsonProperty(value=\"{field['name']}\", access=JsonProperty.Access.READ_ONLY)\n"
1471
- property_def += f"{INDENT}public String get{pascal(field_name)}() {{ return {safe_field_name}.name(); }}\n"
1509
+ property_def += f"{INDENT}public String get{pascal(field_name)}() {{ return {safe_field_name}.avroSymbol(); }}\n"
1472
1510
  else:
1473
1511
  property_def += f"{INDENT}public {field_type.type_name} get{pascal(field_name)}() {{ return {safe_field_name}; }}\n"
1474
1512
  else:
@@ -1651,14 +1689,14 @@ class AvroToJava:
1651
1689
  jackson_annotation=self.jackson_annotations
1652
1690
  )
1653
1691
  elif type_kind == "enum":
1654
- # Convert symbols to Java-safe identifiers (same logic as generate_enum)
1692
+ # Convert symbols to Java-safe identifiers in SCREAMING_CASE (same logic as generate_enum)
1655
1693
  raw_symbols = avro_schema.get('symbols', [])
1656
1694
  java_safe_symbols = []
1657
1695
  for symbol in raw_symbols:
1658
- java_symbol = symbol.replace('-', '_').replace('.', '_')
1696
+ java_symbol = symbol.replace('-', '_').replace('.', '_').upper()
1659
1697
  if java_symbol and java_symbol[0].isdigit():
1660
1698
  java_symbol = '_' + java_symbol
1661
- if is_java_reserved_word(java_symbol):
1699
+ if is_java_reserved_word(java_symbol.lower()):
1662
1700
  java_symbol = '_' + java_symbol
1663
1701
  java_safe_symbols.append(java_symbol)
1664
1702
 
@@ -1808,9 +1846,15 @@ class AvroToJava:
1808
1846
  # Generate test value for the field
1809
1847
  if "const" in field and field["const"] is not None:
1810
1848
  const_value = field["const"]
1811
- # For enum types, qualify with the enum type name
1849
+ # For enum types, qualify with the enum type name and convert to SCREAMING_CASE
1812
1850
  if is_enum or (field_type.type_name not in ('String', 'int', 'Integer', 'long', 'Long', 'double', 'Double', 'boolean', 'Boolean')):
1813
- test_value = f'{field_type.type_name}.{const_value}'
1851
+ # Convert enum const value to uppercase to match Java enum constant naming convention
1852
+ const_value_upper = str(const_value).replace('-', '_').replace('.', '_').upper()
1853
+ if const_value_upper and const_value_upper[0].isdigit():
1854
+ const_value_upper = '_' + const_value_upper
1855
+ if is_java_reserved_word(const_value_upper.lower()):
1856
+ const_value_upper = '_' + const_value_upper
1857
+ test_value = f'{field_type.type_name}.{const_value_upper}'
1814
1858
  else:
1815
1859
  test_value = f'"{const_value}"'
1816
1860
  else:
@@ -1896,12 +1940,12 @@ class AvroToJava:
1896
1940
  avro_schema = self.generated_avro_schemas.get(java_type, {})
1897
1941
  symbols = avro_schema.get('symbols', [])
1898
1942
  if symbols:
1899
- # Convert symbol to valid Java identifier (same logic as in generate_enum)
1900
- first_symbol = symbols[0].replace('-', '_').replace('.', '_')
1943
+ # Convert symbol to valid Java identifier in SCREAMING_CASE (same logic as in generate_enum)
1944
+ first_symbol = symbols[0].replace('-', '_').replace('.', '_').upper()
1901
1945
  if first_symbol and first_symbol[0].isdigit():
1902
1946
  first_symbol = '_' + first_symbol
1903
1947
  # Check if the symbol is a Java reserved word and prefix with underscore
1904
- if is_java_reserved_word(first_symbol):
1948
+ if is_java_reserved_word(first_symbol.lower()):
1905
1949
  first_symbol = '_' + first_symbol
1906
1950
  # Use fully qualified name to avoid conflicts with field names
1907
1951
  return f'{java_type}.{first_symbol}'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structurize
3
- Version: 2.18.1
3
+ Version: 2.18.2
4
4
  Summary: Tools to convert from and to JSON Structure from various other schema languages.
5
5
  Author-email: Clemens Vasters <clemensv@microsoft.com>
6
6
  Classifier: Programming Language :: Python :: 3
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes