Outputting an EObject to a string for debugging or logging [message #504169] |
Thu, 17 December 2009 14:41 |
Nikita Missing name Messages: 32 Registered: October 2009 |
Member |
|
|
I was wondering if there is a utility to output an EObject to a string that is easy to read for debugging or logging? For example, if I have an EObject of type PersonType, this toString could look something like this:
PersonType
firstName: John (String)
lastName: Smith (String)
address: (AddressType)
streetNum: 123 (Integer)
...
Maybe the right solution is to just serialize the EObject to XML? The only trick would be to ensure that the code does not modify the EObject (if it's contained in a resource or another object). Is the best solution for this to just copy the EObject using EcoreUtil.copy() before serializing it?
Thank you!
Nikita
[Updated on: Thu, 17 December 2009 14:43] Report message to a moderator
|
|
|
Re: Outputting an EObject to a string for debugging or logging [message #504192 is a reply to message #504169] |
Thu, 17 December 2009 15:58 |
Ed Merks Messages: 33139 Registered: July 2009 |
Senior Member |
|
|
Nikita,
The generated toString method tries to do a reasonable job, but it needs
to be careful about printing references because that can easily lead to
circularity. You could certainly create a copy and put that in an XML
resource to serialize it that way.
Nikita wrote:
> I was wondering if there is a utility to output an EObject to a string
> that is easy to read for debugging or logging? For example, if I have
> an EObject of type PersonType, this toString could look something like
> this:
>
>
> PersonType
> firstName: John (String)
> lastName: Smith (String)
> address: (AddressType)
> streetNum: 123 (Integer)
> ..
>
>
> Maybe the right solution is to just serialize the EObject to XML? The
> only trick would be to ensure that the code does not modify the
> EObject (if it's contained in a resource or another object). Is the
> best solution for this to just copy the EObject using EcoreUtil.copy()
> before serializing it?
>
> Thank you!
> Nikita
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02916 seconds