Skip to content

Conversation

rohanlopes20
Copy link

Create new PR based on @cowtowncoder comments

#5064 (comment)

@yawkat
Copy link
Member

yawkat commented Sep 9, 2025

i havent followed the discussion, i dont know whether the name is settled yet, and i dont feel strongly about it, but how about 'readAutomatic' instead? it makes it clear that additional magic is happening, 'automatic' is similar to C++ auto, and it is still short enough to not be cumbersome.

@rohanlopes20
Copy link
Author

i havent followed the discussion, i dont know whether the name is settled yet, and i dont feel strongly about it, but how about 'readAutomatic' instead? it makes it clear that additional magic is happening, 'automatic' is similar to C++ auto, and it is still short enough to not be cumbersome.

@cowtowncoder can you suggest.

@cowtowncoder
Copy link
Member

I'll have to think about this: I do not think readObject() works.

My initial thinking is/was that we would just have a method for resolving type to create ObjectReader; but I am not sure what would be good name for that method.

Maybe ObjectReader forAutomaticType(...) or forDetectedType(...)?

@rohanlopes20
Copy link
Author

I'll have to think about this: I do not think readObject() works.

My initial thinking is/was that we would just have a method for resolving type to create ObjectReader; but I am not sure what would be good name for that method.

Maybe ObjectReader forAutomaticType(...) or forDetectedType(...)?

Something like this ? @cowtowncoder. Also, are we going to remove method added for readObject?

    public <T> ObjectReader forAutomaticType(T... reified) {
        Type type = getClassOf(reified);
        _assertNotNull("type", type);
        return _newReader(deserializationConfig(), _typeFactory.constructType(type), null,
                null, _injectableValues);
    }

and test

        final String JSON = "[1]";
        JsonParser p = MAPPER.createParser(JSON);
        Object ob = MAPPER.forAutomaticType()
                .readValue(p);
        p.close();
        assertTrue(ob instanceof List<?>);

@cowtowncoder
Copy link
Member

Yes, remove readObject(). And test should probably use target types other than java.lang.Object (although that can also be used) to ensure actual type introspection -- Object is "untyped" target, which maps JSON array as List anyway.

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

Successfully merging this pull request may close these issues.

3 participants