users@jaxb.java.net

Re: Is java.util.Map supported in JAXB 2.0

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 28 Apr 2009 09:02:34 +0200

Well, "hierarchy" is the natural structuring principle of XML and is most
naturally represented by Java classes using a List<HierarchyNode> to store a
node's children. This doesn't make much difference for the application, so
why use Set? It seems to me that your node classes aren't intended for being
used in the typical set operations. ArrayList requires less memory than
HashSet, and it won't be slower on certain operations unless nodes have many
children.

Note that the access to all of a node's children is invariably written like
this:
   (for HierarchyNode n: parent.getHierarchyNodes() ){
         ...n.methodX()...
   }

The only thing a Set would do for you is to block the (accidental) insertion
of a duplicate, but is this an issue?

-W


On Tue, Apr 28, 2009 at 5:41 AM, slrosh <snrpriyadarshana_at_yahoo.com> wrote:

>
>
>
> Hi
>
> I have a existing class and I want to expose this class as a web
> service....
>
> public interface IHierarchyFacade()
> {
> Hierarchy addHierarchy(Hierarchy hierarchy );
> }
>
> ::Hierarchy class::
>
> public class Hierarchy implements Serializable {
>
> /** The Constant serialVersionUID. */
> private static final long serialVersionUID = 8061706495012574352L;
>
> /** The hierarchy id. */
> private Long hierarchyId;
>
> /** The hierarchy name. */
> private String hierarchyName;
> .........
> .........
> /** The hierarchy nodes. */
> private Set<HierarchyNode> hierarchyNodes;
>
> }
>
> HierarchyNode is also a class::
>
> public class HierarchyNode implements Serializable {
>
> /** The hierarchy id. */
> private Long hierarchyId;
>
> /** The node id. */
> private Long nodeId;
>
> /** The parent node id. */
> private Long parentNodeId;
>
> ....................
> ....................
> ....................
> /** The hierarchy nodes. */
> private Set<HierarchyNode> hierarchyNodes;
>
> }
>
>
> This is the structure of the project....
>
> I think JAXB not suported to java collection like java.util.Set
>
>
>
>
>
>
> Wolfgang Laun-2 wrote:
> >
> > Be more specific. Do you want to customize a schema, or do you want to do
> > this by annotations to existing Java classes? What's the type of the
> > Set<?>
> > element? What XML representation do you have?
> > -W
> >
> > On Fri, Apr 24, 2009 at 12:43 PM, slrosh <snrpriyadarshana_at_yahoo.com>
> > wrote:
> >
> >>
> >>
> >> Hi... I am new to JAXB... I want to know how to write a wrapper class
> for
> >> java.util.Set collection...
> >>
> >>
> >>
> >> Felipe Gaucho wrote:
> >> >
> >> > XML Schema does not support Maps :(
> >> >
> >> > you must create your own wrapper to represent a Map as XML data
> >> >
> >> > On Mon, Mar 31, 2008 at 2:41 AM, raags <apparna_at_gmail.com> wrote:
> >> >>
> >> >> Hi, I'm new to JAXB and I noticed a problem when I deployed a web
> >> >> service
> >> >> which had a method that returned a Map. JAXB threw an error stating
> >> that
> >> >> Map
> >> >> is an interface, and JAXB does not support interfaces.
> >> >> @WebMethod
> >> >> public Map<String, String> findAllXYZ(HashMap map)
> >> >> {
> >> >> return map;
> >> >> }
> >> >>
> >> >> JAXB spec states this..
> >> >> 8.5.4 Collections
> >> >> The following collection must be supported:
> >> >> java.util.Map and its subtypes (e.g. java.util.HashMap)
> >> >> java.util.Collection and it's subtypes (e.g. java.util.List)
> >> >>
> >> >> Can someone throw any light on this issue please?
> >> >>
> >> >> Thanks,
> >> >> Raags
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://www.nabble.com/Is-java.util.Map-supported-in-JAXB-2.0-tp16389809p16389809.html
> >> >> Sent from the java.net - jaxb users mailing list archive at
> >> Nabble.com.
> >> >>
> >> >>
> >> >>
> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> >> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >> >>
> >> >>
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> >> > For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >> >
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Is-java.util.Map-supported-in-JAXB-2.0-tp16389809p23213785.html
> >> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Is-java.util.Map-supported-in-JAXB-2.0-tp16389809p23269607.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>