Search code examples
javaserializationavroignite

How can I get field types and values of java object?


Perhaps somebody will be able to advise on how can I reveal the structure of ignite-stored objects having no access to the initial java class (used for object's creation)?Ignite-stored object is simply a java object as far as I understand. By 'structure' I mean field names and types. General purpose is avro schema generation for ignite-stored objects.

Resolved as follows: My final solution now looks like as follows:

private void binObjFieldsParsing(BinaryObject o){
        Map<String, String> fieldNamesNTypes = new LinkedHashMap<String, String>();
        for (String field: o.type().fieldNames()){
            fieldNamesNTypes.put(field, o.type().fieldTypeName(field));
        }

        for (Map.Entry<String, String> fieldNameNType: fieldNamesNTypes .entrySet()){
            System.out.println("Field name: " + fieldNameNType.getKey() + " Field type: " + fieldNameNType.getValue());
        }
    }

Solution

  • You should use binary objects API.

    In short:

    BinaryObject val = (BinaryObject)cache.withKeepBinary().get(key);