unwanted class attribute in @ElementList

View: New views
7 Messages — Rating Filter:   Alert me  

unwanted class attribute in @ElementList

by Schmilinsky, Remsy-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi. I need to get rid of  class="java.util.ArrayList"attribute  when a list is generated, it’s there something available to do this ? Otherwise the resulting xml won’t comply with the schema, example of rendered content:

 

<ListItems class="java.util.ArrayList">

.

.

.

</ListItems

 

Thanks


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

Re: unwanted class attribute in @ElementList

by patb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Remsy,

> Hi. I need to get rid of class="java.util.ArrayList"attribute when a
> list is generated, it’s there something available to do this ?
> Otherwise the resulting xml won’t comply with the schema, example of
> rendered content:

you have to specify a concrete implemention of the list interface in
your class.

So instead of having

  "List< WhatEver > myList;"

in your class you use

  "ArrayList< WhatEver > myList;"

Otherwise SimpleXML can't know which implementation to use.



Regards,
Timo Rumland



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

Re: unwanted class attribute in @ElementList

by niall.gallagher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi,
 
There is a nice way to get rid of the class="java.util.ArrayList" using a Strategy implementation. I have been meaning to add this to the tutorial, and will get to it soon. There should be an example in the test cases.
 
Niall
 
Niall Gallagher
RBS Global Banking & Markets
Office: +44 7879498724

 


From: Schmilinsky, Remsy [mailto:Remsy.Schmilinsky@...]
Sent: 27 August 2009 17:24
To: simple-support@...
Subject: [Simple-support] unwanted class attribute in @ElementList

Hi. I need to get rid of  class="java.util.ArrayList"attribute  when a list is generated, it’s there something available to do this ? Otherwise the resulting xml won’t comply with the schema, example of rendered content:

 

<ListItems class="java.util.ArrayList">

.

.

.

</ListItems

 

Thanks

***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. 
Authorised and regulated by the Financial Services Authority. 
 
This e-mail message is confidential and for use by the 
addressee only. If the message is received by anyone other 
than the addressee, please return the message to the sender 
by replying to it and then delete the message from your 
computer. Internet e-mails are not necessarily secure. The 
Royal Bank of Scotland plc does not accept responsibility for 
changes made to this message after it was sent. 

Whilst all reasonable care has been taken to avoid the 
transmission of viruses, it is the responsibility of the recipient to 
ensure that the onward transmission, opening or use of this 
message and any attachments will not adversely affect its 
systems or data. No responsibility is accepted by The 
Royal Bank of Scotland plc in this regard and the recipient should carry 
out such virus and other checks as it considers appropriate. 

Visit our website at www.rbs.com

***********************************************************************************

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

Parent Message unknown Re: unwanted class attribute in @ElementList

by jpkutner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I sent this out yesterday but I think I forgot to reply-all:

There is another option.  You have to define what implementation of
List you are using, but you could do that in the Strategy.  For
example you could marshal and  your object with this serializer:

       Serializer serializer = new Persister(new TreeStrategy() {
            @Override
            public boolean setElement(Class field, Object value,
NodeMap node, Map map) {
                node.remove("class");
                return false;
            }
        });

In that implementation of TreeStrategy I'm simply striping out the
class attribute - but you will need it to unmarshal.  So when you
unmarshal you can put it back in with this serializer:

      serializer = new Persister(new TreeStrategy() {
            @Override
            public Value getElement(Class field, NodeMap node, Map
map) throws Exception {
                if (field.equals(List.class)) {
                    node.put("class", ArrayList.class.getName());
                }
                return null;
            }
        });

In that implementation of TreeStrategy I'm putting the attribute back,
but I still have to define what impl of List to use.  Hope this helps

Joe Kutner



On Thu, Aug 27, 2009 at 12:03 PM, Timo Rumland<cr@...> wrote:

> Hello Remsy,
>
>> Hi. I need to get rid of class="java.util.ArrayList"attribute when a
>> list is generated, it’s there something available to do this ?
>> Otherwise the resulting xml won’t comply with the schema, example of
>> rendered content:
>
> you have to specify a concrete implemention of the list interface in
> your class.
>
> So instead of having
>
>  "List< WhatEver > myList;"
>
> in your class you use
>
>  "ArrayList< WhatEver > myList;"
>
> Otherwise SimpleXML can't know which implementation to use.
>
>
>
> Regards,
> Timo Rumland
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Simple-support mailing list
> Simple-support@...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

Re: unwanted class attribute in @ElementList

by niall.gallagher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Ya, thats pretty much the way to go with removing the class= attribute. You just need to have a default type to use. A safer way would be.

 Strategy strategy = new TreeStrategy() {
            @Override
            public boolean setElement(Class field, Object value, NodeMap node, Map map) {
                boolean value = super.setElement(field, value, node, map);
                node.remove("class");
                return false;
            }

              @Override
            public Value getElement(Class field, NodeMap node, Map map) throws Exception {
                if (field.equals(List.class)) {
                    node.put("class", ArrayList.class.getName());
                }
                return super.getElement(field, node, map);
            }
};

This will also work with the CycleStrategy. It should be very easy to implement your own strategy implementation with whatever behaviour you like.

Niall


Niall Gallagher
RBS Global Banking & Markets
Office: +44 7879498724  

-----Original Message-----
From: Joe Kutner [mailto:jpkutner@...]
Sent: 28 August 2009 14:38
To: simple-support@...
Subject: Re: [Simple-support] unwanted class attribute in @ElementList

I sent this out yesterday but I think I forgot to reply-all:

There is another option.  You have to define what implementation of List you are using, but you could do that in the Strategy.  For example you could marshal and  your object with this serializer:

       Serializer serializer = new Persister(new TreeStrategy() {
            @Override
            public boolean setElement(Class field, Object value, NodeMap node, Map map) {
                node.remove("class");
                return false;
            }
        });

In that implementation of TreeStrategy I'm simply striping out the class attribute - but you will need it to unmarshal.  So when you unmarshal you can put it back in with this serializer:

      serializer = new Persister(new TreeStrategy() {
            @Override
            public Value getElement(Class field, NodeMap node, Map
map) throws Exception {
                if (field.equals(List.class)) {
                    node.put("class", ArrayList.class.getName());
                }
                return null;
            }
        });

In that implementation of TreeStrategy I'm putting the attribute back, but I still have to define what impl of List to use.  Hope this helps

Joe Kutner



On Thu, Aug 27, 2009 at 12:03 PM, Timo Rumland<cr@...> wrote:

> Hello Remsy,
>
>> Hi. I need to get rid of class="java.util.ArrayList"attribute when a
>> list is generated, it's there something available to do this ?
>> Otherwise the resulting xml won't comply with the schema, example of
>> rendered content:
>
> you have to specify a concrete implemention of the list interface in
> your class.
>
> So instead of having
>
>  "List< WhatEver > myList;"
>
> in your class you use
>
>  "ArrayList< WhatEver > myList;"
>
> Otherwise SimpleXML can't know which implementation to use.
>
>
>
> Regards,
> Timo Rumland
>
>
>
> ----------------------------------------------------------------------
> -------- Let Crystal Reports handle the reporting - Free Crystal
> Reports 2008 30-Day trial. Simplify your report design, integration
> and deployment - and focus on what you do best, core application
> coding. Discover what's new with Crystal Reports now.  
> http://p.sf.net/sfu/bobj-july 
> _______________________________________________
> Simple-support mailing list
> Simple-support@...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now.  http://p.sf.net/sfu/bobj-july _______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority.
 
This e-mail message is confidential and for use by the
addressee only. If the message is received by anyone other
than the addressee, please return the message to the sender
by replying to it and then delete the message from your
computer. Internet e-mails are not necessarily secure. The
Royal Bank of Scotland plc does not accept responsibility for
changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the
transmission of viruses, it is the responsibility of the recipient to
ensure that the onward transmission, opening or use of this
message and any attachments will not adversely affect its
systems or data. No responsibility is accepted by The
Royal Bank of Scotland plc in this regard and the recipient should carry
out such virus and other checks as it considers appropriate.

Visit our website at www.rbs.com

***********************************************************************************


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

Re: unwanted class attribute in @ElementList

by patb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Niall,

> There is a nice way to get rid of the class="java.util.ArrayList"
> using a Strategy implementation. I have been meaning to add this to
> the tutorial, and will get to it soon.

is there a chance that you may drop a note on the mailing list, every
time you extend the tutorials page? It would be great to get notified
about these things.


Thanks!


Best regards,
Timo



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support

Re: unwanted class attribute in @ElementList

by Niall Gallagher-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I've been meaning to adding to the tutorial but have not had a chance. Ill let you know when I do.

Niall

--- On Fri, 8/28/09, Timo Rumland <cr@...> wrote:

> From: Timo Rumland <cr@...>
> Subject: Re: [Simple-support] unwanted class attribute in @ElementList
> To: simple-support@...
> Date: Friday, August 28, 2009, 1:53 PM
> Hello Niall,
>
> > There is a nice way to get rid of the
> class="java.util.ArrayList"
> > using a Strategy implementation. I have been meaning
> to add this to
> > the tutorial, and will get to it soon.
>
> is there a chance that you may drop a note on the mailing
> list, every
> time you extend the tutorials page? It would be great to
> get notified
> about these things.
>
>
> Thanks!
>
>
> Best regards,
> Timo
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal
> Reports 2008 30-Day
> trial. Simplify your report design, integration and
> deployment - and focus on
> what you do best, core application coding. Discover what's
> new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Simple-support mailing list
> Simple-support@...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>


     

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-support mailing list
Simple-support@...
https://lists.sourceforge.net/lists/listinfo/simple-support