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

field of type Set is returing incorrect type (easy fix) #1291

Closed
richarddd opened this issue Nov 21, 2018 · 0 comments
Closed

field of type Set is returing incorrect type (easy fix) #1291

richarddd opened this issue Nov 21, 2018 · 0 comments
Labels
Milestone

Comments

@richarddd
Copy link
Contributor

Hi,

Discovered this today inside: DefaultCreator.java

public <T> T createInstance(final Class<T> clazz) {
        try {
            return getNoArgsConstructor(clazz).newInstance();
        } catch (Exception e) {
            if (Collection.class.isAssignableFrom(clazz)) {
                return (T) createList(null);
            } else if (Map.class.isAssignableFrom(clazz)) {
                return (T) createMap(null);
            } else if (Set.class.isAssignableFrom(clazz)) {
                return (T) createSet(null);
            }
            throw new MappingException("No usable constructor for " + clazz.getName(), e);
        }
    }

Problem is that an Set class is also a collection. To solve it just flip the if statments like so:

if (Set.class.isAssignableFrom(clazz)) {
                return (T) createSet(null);
            } else if (Map.class.isAssignableFrom(clazz)) {
                return (T) createMap(null);
            } else if (Collection.class.isAssignableFrom(clazz)) {
                return (T) createList(null);
            }

I would create a PR but i have some issues with my repo... :(

@evanchooly evanchooly added this to the 1.5.0 milestone Jan 22, 2019
@evanchooly evanchooly added the bug label Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants