Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Deserializing EMap<String, Object>
Deserializing EMap<String, Object> [message #419258] Thu, 15 May 2008 10:37 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.tools.emf.verbose.de

Hi,

I am using an EMap<String, Object> as a property map. When I use
references to other objects as the value, serialization and
deserialization to and from XML is working fine:

<properties key="model" value="//@models.1"/>

However, when the value is a String, the String is stored as a literal:

<properties key="optional" value="false"/>

This causes problems when deserializing:

java.lang.IllegalArgumentException: The value 'false' is invalid.
at
org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFa ctoryImpl.java:439)

After checking the implementation of EFactoryImpl, this is the expected
behavior, as Object is neither derived, a union type, an item type, or a
primitive type, and there is no constructor Object(String) either. What
seems to be missing as the last fallback is the check that a String is an
Object, making it okay to just use the provided String as is.

Is this a bug, or am I doing something wrong? Or is there a workaround?
Before, I was using an EMap<String, String>, which worked fine, but I'd
rather not have to use to separate maps for Strings and Object
references...

Thanks,

Florian
Re: Deserializing EMap<String, Object> [message #419262 is a reply to message #419258] Thu, 15 May 2008 14:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Florian,

Comments below.

Florian Klein wrote:
> Hi,
>
> I am using an EMap<String, Object> as a property map. When I use
> references to other objects as the value, serialization and
> deserialization to and from XML is working fine:
>
> <properties key="model" value="//@models.1"/>
>
> However, when the value is a String, the String is stored as a literal:
>
> <properties key="optional" value="false"/>
>
> This causes problems when deserializing:
>
> java.lang.IllegalArgumentException: The value 'false' is invalid.
> at
> org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFa ctoryImpl.java:439)
>
>
> After checking the implementation of EFactoryImpl, this is the
> expected behavior, as Object is neither derived, a union type, an item
> type, or a primitive type, and there is no constructor Object(String)
> either. What seems to be missing as the last fallback is the check
> that a String is an Object, making it okay to just use the provided
> String as is.
Generally you need to provide your own createAbcFromString and
convertAbcToString for your EDataType Abc in your generated
XyzFactoryImpl. I'm not sure how you have it specialized to produce an
IDREF in some cases.
>
> Is this a bug, or am I doing something wrong? Or is there a
> workaround? Before, I was using an EMap<String, String>, which worked
> fine, but I'd rather not have to use to separate maps for Strings and
> Object references...
Object as a type type is quite problematic. There is an EJavaObject
EDataType, but it serializes using java.io.Serializeable, so while it
works okay for Objects that are serializeable, it doesn't produce human
readable results. The general problem is that if you put an Integer in
the map and serialize, presumably you want and Integer coming back, and
not a String. Perhaps the XMLTypePackage's AnySimpleType EDataType will
be more like what you want...
>
> Thanks,
>
> Florian
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deserializing EMap<String, Object> [message #419323 is a reply to message #419262] Mon, 19 May 2008 09:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.tools.emf.verbose.de

Ed,

thanks for your quick response.

> Generally you need to provide your own createAbcFromString and
> convertAbcToString for your EDataType Abc in your generated
> XyzFactoryImpl. I'm not sure how you have it specialized to produce an
> IDREF in some cases.

I have to admit that I'm using EMF somewhat superficially here - I
maintain my meta model in Rational Rose and import that into an EMF
project using the supplied wizard, leaving all the transformations to it.
So I suppose that because the types that I place into the property map
come from my meta model and are part of the same genmodel, the correct
converters get created.

> Object as a type type is quite problematic. There is an EJavaObject
> EDataType, but it serializes using java.io.Serializeable, so while it
> works okay for Objects that are serializeable, it doesn't produce human
> readable results. The general problem is that if you put an Integer in
> the map and serialize, presumably you want and Integer coming back, and
> not a String.

That is of course true, just falling back to String will produce
unexpected results. So the real question is rather - why is there no
generic support for the basic types (primitive types, String, possibly
also Java number classes and collections) when serializing? I.e. if EMF
serializes a reference of type Object pointing to a String "5" rsp. an
Integer 5, the type information is available at the time and could be
stored in the XML while maintaining a human readable format. But, ignoring
how serialization is designed in detail, this is probably problematic in
other ways.

I will experiment with EJavaObject. Alternatively, I can always wrap
Strings in custom objects that would get serialized properly, or just use
separate property maps for Strings and Object reference, each of which
works fine individually. Neither strikes me a particularly elegant,
though...

Thanks & regards,

Florian
Re: Deserializing EMap<String, Object> [message #419333 is a reply to message #419323] Mon, 19 May 2008 12:53 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Florian,

Comments below.

Florian Klein wrote:
> Ed,
>
> thanks for your quick response.
>
>> Generally you need to provide your own createAbcFromString and
>> convertAbcToString for your EDataType Abc in your generated
>> XyzFactoryImpl. I'm not sure how you have it specialized to produce
>> an IDREF in some cases.
>
> I have to admit that I'm using EMF somewhat superficially here - I
> maintain my meta model in Rational Rose and import that into an EMF
> project using the supplied wizard, leaving all the transformations to
> it. So I suppose that because the types that I place into the property
> map come from my meta model and are part of the same genmodel, the
> correct converters get created.
>> Object as a type type is quite problematic. There is an EJavaObject
>> EDataType, but it serializes using java.io.Serializeable, so while it
>> works okay for Objects that are serializeable, it doesn't produce
>> human readable results. The general problem is that if you put an
>> Integer in the map and serialize, presumably you want and Integer
>> coming back, and not a String.
>
> That is of course true, just falling back to String will produce
> unexpected results. So the real question is rather - why is there no
> generic support for the basic types (primitive types, String, possibly
> also Java number classes and collections) when serializing?
Which collection of types should be supported? How will I distinguish
the String "1", Integer "1", the int "1", the Character "1", and so on
from each other so that when I serialize I'd know what type of thing to
create. I'd kind of have to invent a syntax for that, and it would
apply for some limited set of types...
> I.e. if EMF serializes a reference of type Object pointing to a String
> "5" rsp. an Integer 5, the type information is available at the time
> and could be stored in the XML while maintaining a human readable
> format. But, ignoring how serialization is designed in detail, this is
> probably problematic in other ways.
It's certainly possible to do such a thing, but of course the user can
do that as well....
>
> I will experiment with EJavaObject. Alternatively, I can always wrap
> Strings in custom objects that would get serialized properly, or just
> use separate property maps for Strings and Object reference, each of
> which works fine individually. Neither strikes me a particularly
> elegant, though...
I don't know if there is a general and elegant way to hand this...
>
> Thanks & regards,
>
> Florian
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Migration::EMF generated base to having only an ecore file
Next Topic:Programmatically moving Packages within an UML model
Goto Forum:
  


Current Time: Thu Mar 28 13:22:24 GMT 2024

Powered by FUDForum. Page generated in 0.02596 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top