Giter Club home page Giter Club logo

jackson-antpathfilter's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jackson-antpathfilter's Issues

convertValue not working correctly with antpathfilter

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.

Jackson2Helper and object mapper configuration is not threadsafe

Jackson2Helper instance is uses a common object mapper shared across all requests, so if one of the requests sets specific properties for filtering, then a request happening around the same could accidentally use the same property filter.

Is there a way to re use object mapper?

how to: filtering of nested array objects

Hello,

Thanks for the addon - works great. I have a new request, which is to support filtering of nested array objects. How could achieve that?

For example:

{
    "user_id": 123,
    "name": "foo",
    "roles": [
        {
            "name": "ROLE_USER",
            "description": "Regular users."
        },
        {
            "name": "ROLE_ADMIN",
            "description": "Administrators."
        }
    ]
}

How to filter out the roles[*].description from the above Json string? Thanks!

addMixInAnnotations instead of addMixIn

To make the example working i had to change this line:
mapper.addMixIn(Object.class, AntPathFilterMixin.class);
to
mapper.addMixInAnnotations(Object.class, AntPathFilterMixin.class);

I am using jackson 2.8.1

Support objects other than java beans

I have a requirement to filter Json objects using Ant like paths. AntPathFilter library sounds like a perfect solution but unfortunately my data is in flexible data structures such as Jackson ObjectNode and Java Map. I couldn't get it to work with Jackson ObjectNode.

	@Test
	public void testAntPathFilterObject()  throws Exception {
		ObjectNode user = JsonNodeFactory.instance.objectNode();
		user.put("name", "Venkat").put("dept", "Eng").putObject("manager").put("name", "Scot").put("dept", "Eng");
		
		String[] filter = new String[] {"!manager"};

		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.addMixIn(Object.class, AntPathFilterMixin.class);

		FilterProvider filterProvider = new SimpleFilterProvider().addFilter("antPathFilter", new AntPathPropertyFilter(filter));
		objectMapper.setFilters(filterProvider);

		String json = objectMapper.writeValueAsString(user);
		System.out.println("json="+json);
	}

This gives me

json={"name":"Venkat","dept":"Eng","manager":{"name":"Scot","dept":"Eng"}}

But the following code with POJO works as expected:

	public void testAntPathFilterPOJO() throws Exception {
		User user = new User();
		User manager = new User();
		
		manager.setName("Scot");
		manager.setDept("Eng");
		
		user.setName("Venkat");
		user.setDept("Eng");
		user.setManager(manager);
		
		String[] filter = new String[] {"!manager"};

		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.addMixIn(Object.class, AntPathFilterMixin.class);

		FilterProvider filterProvider = new SimpleFilterProvider().addFilter("antPathFilter", new AntPathPropertyFilter(filter));
		objectMapper.setFilters(filterProvider);

		String json = objectMapper.writeValueAsString(user);
		System.out.println("json="+json);
	}

This produces intended result:

json={"name":"Venkat","dept":"Eng"}

Does the library work with non-POJOs? It will be great to have AntPathFilter working with non-POJO such as Jackson JsonNode, Map, etc.

Filtering an array

Hi,

I've got the following json :

[
	{
		"id": "test",
		"firstName": "Hello",
		"lastName": "World"
	}
]

I know it's not an object, it's my entity list inserted into a paginate element. Is it possible to filter on such case ? I couldn't make it work.

Cheers

Spring Boot 2 (Spring 5): Cannot resolve PropertyFilter with id 'antPathFilter'

Using Spring Boot 2.0.4.RELEASE, which is based on Spring 5.0.8.RELEASE.

When following the instructions to setup the AntPathFilter for "Spring 4.2.2+", that is, extending DelegatingWebMvcConfiguration, then an exception occurs in cases when the AntPathFilter should not be applied. (The problem is somewhat similar to this post on SO.) Things work fine for controller methods that apply the AntPathFilter for serialization of their response body.

This configuration creates problems for controllers that do not apply the AntPathFilter:

@Configuration
public class WebConfig extends DelegatingWebMvcConfiguration {
    @Override
    public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
        // Add a MappingJackson2HttpMessageConverter so that
        // objectMapper.writeFiltered
        // is using the objectMapper configured with the needed Mixin
        ObjectMapper objectMapper = Jackson2ObjectMapperBuilder
            .json()
            .mixIn(Object.class, AntPathFilterMixin.class)
            .build();
        messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));
        addDefaultHttpMessageConverters(messageConverters);
    }
}

When a controller doesn't use the AntPathFilter, the following exception occurs:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot resolve PropertyFilter with id 'antPathFilter'; no FilterProvider configured
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.9.6.jar:2.9.6]
	at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1191) ~[jackson-databind-2.9.6.jar:2.9.6]
	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:312) ~[jackson-databind-2.9.6.jar:2.9.6]
	at com.fasterxml.jackson.databind.ser.std.StdSerializer.findPropertyFilter(StdSerializer.java:426) ~[jackson-databind-2.9.6.jar:2.9.6]
...

java.lang.OutOfMemoryError: GC overhead limit exceeded with version 1.0.2

Hi. I'm using version 1.0.0 and when there is a loop in collections, I get "infinite recursion" Jackson error showing the relation that is causing the problem but when I've tested new version 1.0.2, I'm only getting "java.lang.OutOfMemoryError: GC overhead limit" error, without any other useful information. Because that I'm using the previous version again.

Your library is very useful to deal with collections, using JPA and REST. So, I'll be attentive to new releases. Thank you very much.

antPathFilter seems to be the only supported filter name

If I try to configure other AntPathPropertyFilters with different names (e.g. MyService -> new AntPathPropertyFilter("**.someproperty") it appears to fail. The library also appears to work only as long as you have a filter of the name antPathFilter. Is there some workaround to allow different names for the path filter? It's entirely possible that I've just missed something, but it wasn't obvious fooling around with it for ~1 hour.

Use with JAX-RS

How to use it with JAX-RS? I tried to set the filter in a WriterInterceptor but subsequent HTTP requests overlaps property filters and the outcome becomes unpredictable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.