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

convertValue not working correctly with antpathfilter #2

Closed
larjohn opened this issue Sep 24, 2015 · 5 comments
Closed

convertValue not working correctly with antpathfilter #2

larjohn opened this issue Sep 24, 2015 · 5 comments

Comments

@larjohn
Copy link

larjohn commented Sep 24, 2015

The following does not work correctly:

            ObjectMapper mapper = buildObjectMapper();

            String[] includedFieldNames = { "id", "judgementNo", "judgementDate" ,"courthouse","courthouse.name", "@loaded"};
            mapper.addMixIn(Object.class, AntPathFilterMixin.class);


            com.fasterxml.jackson.databind.type.CollectionType collectionType =  mapper.getTypeFactory().constructCollectionType(List.class, Object.class);

// Create map

            FilterProvider filterProvider = new SimpleFilterProvider().addFilter("antPathFilter", new AntPathPropertyFilter(includedFieldNames));
            mapper.setFilterProvider(filterProvider);
            List<Object> map = mapper.convertValue(judgements, collectionType);

It does not serialize court properties, so it comes empty in the map. It seems that it does not guess the path correctly in this.include(writer, jgen).

I am out of time currently, so can't provide more details right now, in case you needed them.

@larjohn
Copy link
Author

larjohn commented Sep 24, 2015

Writing as string works fine

@Antibrumm
Copy link
Owner

I have never used the filter for anything else than serialization. Could you please provide me with the implementation of judgements. Ideally with a unittest? ;) I will take a look at it once I got some time.

@larjohn
Copy link
Author

larjohn commented Sep 24, 2015

judgements is a List where Judgement is a class that has a field courthouse, of type Courthouse (fields "name" etc)

I will try to test it myself when I get some time as well, I just reported it in case you had any idea immediately.

@Antibrumm
Copy link
Owner

I took a little look into the issue and i found out that the WriteContexts are created differently within Jackson for writeAsString and convert. This results in an issue during the evaluation of the pathToTest. I will have to dig deeper into the code to see whats happening exactly.

Here's a printout of the two approaches:

Write to String

id
judgementNo
judgementDate
courthouse
courthouse.id
courthouse.name
id
judgementNo
judgementDate
courthouse
courthouse.id
courthouse.name

[{"id":1,"judgementNo":"1","judgementDate":1443856979489,"courthouse":{"name":"Courthouse 1"}},{"id":2,"judgementNo":"2","judgementDate":1443856979491,"courthouse":{"name":"Courthouse 2"}}]

Convert value

id
judgementNo
judgementDate
courthouse
id.id <-- here the parent context contains "id" instead of "courthouse"
id.name
id
judgementNo
judgementDate
courthouse
id.id
id.name

[{id=1, judgementNo=1, judgementDate=1443856979489, courthouse={}}, {id=2, judgementNo=2, judgementDate=1443856979491, courthouse={}}]

Antibrumm pushed a commit that referenced this issue Oct 26, 2015
Showing that convert is not yet working as the JsonStreamContexts are
build differently than when using write, resulting in a non equal
treatment.
@Antibrumm
Copy link
Owner

Jackson fixes the issue in version 2.6.4
FasterXML/jackson-databind#984

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

2 participants