Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to deserialize EnumSet with json without type #120

Closed
sgandon opened this issue Aug 24, 2017 · 3 comments
Closed

failed to deserialize EnumSet with json without type #120

sgandon opened this issue Aug 24, 2017 · 3 comments

Comments

@sgandon
Copy link
Contributor

sgandon commented Aug 24, 2017

When deserializing a json string created using JsonWriter.TYPE set to false, the string cannot be deserialized if it contains an EnumSet, the following code in com.cedarsoftware.util.io.ObjectResolver show that if item.getType() returns null (expected cause no type is written) then classForName() call will fail and throw an exception.
The type could be derived from the real object field type but here the Class c does not have the generic type the information, the Field instance has it but not the Class.

 private Object getEnumSet(Class c, JsonObject<String, Object> jsonObj)
    {
        Object[] items = jsonObj.getArray();
        if (items == null || items.length == 0)
        {
            return newInstance(c, jsonObj);
        }
        JsonObject item = (JsonObject) items[0];
        String type = item.getType();
        Class enumClass = MetaUtils.classForName(type, reader.getClassLoader());
        EnumSet enumSet = null;
        for (Object objectItem : items)
        {
            item = (JsonObject) objectItem;
            Enum enumItem = (Enum) getEnum(enumClass, item);
            if (enumSet == null)
            {   // Lazy init the EnumSet
                enumSet = EnumSet.of(enumItem);
            }
            else
            {
                enumSet.add(enumItem);
            }
        }
        return enumSet;
    }

@jdereg
Copy link
Owner

jdereg commented Aug 24, 2017

This method would need a variant that takes a field - and then that version used in the appropriate places. Probably not a simple smash-and-grab job, though.

@wwang-talend
Copy link
Contributor

here do a fix try for that : #156 seems.

@jdereg
Copy link
Owner

jdereg commented Sep 13, 2023

fixed in release 4.14.1

@jdereg jdereg closed this as completed Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants