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

Calls to ObjectMapper.addMixInAnnotations on an instance returned by ObjectMapper.copy() are ignored #245

Closed
edalquist opened this issue Jun 19, 2013 · 6 comments
Milestone

Comments

@edalquist
Copy link

Below is a chunk of unit test that demonstrates this problem. It should be easy to reproduce with any POJO. I'm using version 2.2.2

    @JsonFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME)
    private interface PortletRenderExecutionEventFilterMixIn {
        static final String FILTER_NAME = "PortletRenderExecutionEventFilter";
    }

    private PortalEvent createEvent() {
        final String sessionId = "1234567890123_system_AAAAAAAAAAA";
        final PortalEvent.PortalEventBuilder eventBuilder = new PortalEvent.PortalEventBuilder(this, "example.com", sessionId, SystemPerson.INSTANCE, null);
        return new PortletRenderExecutionEvent(eventBuilder, new MockPortletWindowId("pw1"), "fname1", 123450000, Collections.<String, List<String>>emptyMap(), false, false);
    }

    @Test
    public void testMixinNoCopy() throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        mapper.findAndRegisterModules();

        mapper.addMixInAnnotations(Object.class, PortletRenderExecutionEventFilterMixIn.class);
        final FilterProvider filterProvider = new SimpleFilterProvider().addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano", "parameters"));
        final ObjectWriter portletEventWriter = mapper.writer(filterProvider);

        final String result = portletEventWriter.writeValueAsString(createEvent());

        assertEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"fname\":\"fname1\",\"executionTimeNano\":123450000,\"parameters\":{}}", result);
    }

    /**
     * Fails as actual output is:
     * {"@c":".PortletRenderExecutionEvent","timestamp":1371671516798,"serverId":"example.com","eventSessionId":"1234567890123_system_AAAAAAAAAAA","userName":"system","fname":"fname1","executionTimeNano":123450000,"parameters":{},"targeted":false,"usedPortalCache":false}
     */
    @Test
    public void testMixinWithCopy() throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        mapper.findAndRegisterModules();

        //Clone from "shared" ObjectMapper
        mapper = mapper.copy();

        mapper.addMixInAnnotations(Object.class, PortletRenderExecutionEventFilterMixIn.class);
        final FilterProvider filterProvider = new SimpleFilterProvider().addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano", "parameters"));
        final ObjectWriter portletEventWriter = mapper.writer(filterProvider);

        final String result = portletEventWriter.writeValueAsString(createEvent());

        assertEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"fname\":\"fname1\",\"executionTimeNano\":123450000,\"parameters\":{}}", result);
    }
@cowtowncoder
Copy link
Member

Would it be possible to include referred classes as well? I can simplify test, but want to make sure it first works exactly as-is.

@cowtowncoder
Copy link
Member

Not sure if this is still valid -- will keep open for a bit, but close without additional information.

@cowtowncoder cowtowncoder changed the title Calls to ObjectMapper.addMixInAnnotations on an instance returned by ObjectMapper.copy() are ingored Calls to ObjectMapper.addMixInAnnotations on an instance returned by ObjectMapper.copy() are ignored Apr 17, 2014
@alan-czajkowski
Copy link

@cowtowncoder this issue still exists for v2.4.2, please re-open

@cowtowncoder
Copy link
Member

Issue was not closed due to not existing, but since reproduction is missing definition of PortalEvent; and so I have no idea how test is supposed to work.

I will re-open this with reproducible test case.

@cowtowncoder
Copy link
Member

Actually, let me see; I was actually able to reproduce this after a failed attempt.

@cowtowncoder cowtowncoder reopened this Oct 29, 2014
@cowtowncoder cowtowncoder modified the milestones: 2l4., 2.4.4 Oct 29, 2014
@cowtowncoder
Copy link
Member

Better late than never; problem was that serializer cache was basically not cleared, so while mix-ins were added, serializers were not being re-constructed.

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