You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by "Bryant Luk (JIRA)" <ji...@apache.org> on 2010/10/28 22:17:22 UTC

[jira] Commented: (WINK-325) Allow AtomCommonAttributes#otherAttributes and AtomCommonAttributesSimpleContent#otherAttributes to be lazy initialized.

    [ https://issues.apache.org/jira/browse/WINK-325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12925930#action_12925930 ] 

Bryant Luk commented on WINK-325:
---------------------------------

Did you change the Jackson JSON Provider (JacksonJsonProvider) configuration from the defaults?  I tried lazily initializing the variable but I think Jackson is using the getter/setter properties before it attempts the instance variables.  The closest I could get to your output was:

{code}
        AtomText a = new AtomText("hello");
        JacksonJsonProvider provider = new JacksonJsonProvider();
        provider.configure(Feature.WRITE_NULL_PROPERTIES, Boolean.FALSE);
        provider.writeTo(a, a.getClass(), a.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE, null, System.out);
{code}

For your use case, I think the easiest solution is to override the getter for otherAttributes:

{code}
    public class MyAtomText extends AtomText {
        
        public MyAtomText(String value) {
            super(value);
        }

        @Override
        public Map<QName, String> getOtherAttributes() {
            Map<QName, String> otherAttributes = super.getOtherAttributes();
            if(otherAttributes.isEmpty()) {
                return null;
            }
            return otherAttributes;
        }  
    }
{code}
    
when using the JacksonJsonProvider:

{code}
        MyAtomText a = new MyAtomText("hello");
        JacksonJsonProvider provider = new JacksonJsonProvider();
        provider.configure(Feature.WRITE_NULL_PROPERTIES, Boolean.FALSE);
        provider.writeTo(a, a.getClass(), a.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE, null, System.out);
{code}

I get:

{code}
{"value":"hello","type":"text"}
{code}

> Allow AtomCommonAttributes#otherAttributes and AtomCommonAttributesSimpleContent#otherAttributes to be lazy initialized.
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: WINK-325
>                 URL: https://issues.apache.org/jira/browse/WINK-325
>             Project: Wink
>          Issue Type: Improvement
>          Components: Common
>    Affects Versions: 1.1.2
>            Reporter: Kaloyan Kolev
>            Priority: Trivial
>             Fix For: 1.1.2
>
>
> I am using the Jackson provider to serialize an AtomText which extends AtomCommonAttributes. 
> For as simple input as:
> {code}
> return new AtomText("someValue");
> {code}
> I get:
> {code}
> {
>   "otherAttributes" : {
>   },
>   "type" : "text",
>   "value" : "someValue"
> }
> {code}
> AtomCommonAttributes#otherAttributes is accessed as in the rest of the Atom* beans. Is it possible to allow the map to be lazily initialized when the AtomCommonAttributes#getOtherAttributes() method is called like in the rest?
> I can see this is also relevant for the AtomCommonAttributesSimpleContent class, so updating the summary.
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.