{"record":{"id":"cf535360c19da4ab","repo":"xai-org/x-algorithm","slug":"thrift-enums-are-not-supported-in-strato-json","errorCode":null,"errorMessage":"Thrift enums are not supported in strato JSON","messagePattern":"Thrift enums are not supported in strato JSON","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/Serializer.java","lineNumber":1586,"sourceCode":"      @Override\n      protected void serialize(TProtocol prot, T value) throws Exception {\n        prot.writeI32(value.getValue());\n      }\n\n      @Override\n      protected T deserialize(TProtocol prot) throws Exception {\n        int v = prot.readI32();\n        return enumMap.get(v);\n      }\n\n      @Override\n      protected void toScript(GenScript script, T value) {\n        script.builder.append(\"NULL\");\n      }\n\n      @Override\n      protected void toStratoJson(GenScript script, T value) {\n        throw new IllegalArgumentException(\"Thrift enums are not supported in strato JSON\");\n      }\n    };\n  }\n\n  public static <T extends ThriftStruct> Serializer<T> thriftStructOf(Class<T> clazz)\n      throws SemanticCheckFailure {\n    try {\n      ThriftStructCodec codec = ThriftStructCodec.forStructClass(clazz);\n\n      return new Serializer<T>() {\n\n        @Override\n        public void computeFingerprint(Hasher hasher, T value) throws TException {\n          TFingerprintProtocol prot = new TFingerprintProtocol(hasher);\n          codec.encode(value, prot);\n        }\n\n        @Override","sourceCodeStart":1568,"sourceCodeEnd":1604,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/Serializer.java#L1568-L1604","documentation":"The thrift enum serializer (thriftEnumOf for TEnum classes) renders enums as NULL in fingerprint scripts but throws IllegalArgumentException in toStratoJson: thrift enums have no strato JSON encoding here. Any feature/constant typed as a thrift enum fails as soon as it goes through the strato JSON path.","triggerScenarios":"Creating a serializer via Serializer.thriftEnumOf(EnumClass.class) and invoking genStratoJson with any enum value (even a valid one).","commonSituations":"Rule predicates referencing thrift enum constants that are then exported/served via strato; assuming enums serialize like strings; adding an enum-typed field to a strato-served feature.","solutions":["Convert the enum to its integer value or name string before strato JSON serialization and serialize with intOf()/stringOf().","Model the field as an I32/string in the serving schema and map the enum at the edges.","Extend toStratoJson in the enum serializer to emit the enum's name/value if the strato format can accept it."],"exampleFix":"// before\nSerializer.thriftEnumOf(MyEnum.class).genStratoJson(script, MyEnum.A);\n// throws Thrift enums are not supported in strato JSON\n\n// after\nSerializer.intOf().genStratoJson(script, MyEnum.A.getValue());\n// or\nSerializer.stringOf().genStratoJson(script, MyEnum.A.name());","handlingStrategy":"fallback","validationCode":"if (value instanceof TEnum) {\n  value = ((TEnum) value).getValue(); // serialize as int\n}","typeGuard":"static boolean isThriftEnum(Class<?> c) {\n  return TEnum.class.isAssignableFrom(c);\n}","tryCatchPattern":"catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Thrift enums\")) {\n    return serializeAsIntOrName(enumValue);\n  }\n  throw e;\n}","preventionTips":["Map thrift enums to int/string at the boundary before serialization.","Avoid enum-typed fields in strato-served feature schemas.","Test enum-typed constants through both fingerprint and strato JSON paths."],"tags":["strato-json","thrift-enum","serialization","java"],"backgroundTag":"unsupported-type-for-strato-json","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}