Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Outputting an EObject to a string for debugging or logging
Outputting an EObject to a string for debugging or logging [message #504169] Thu, 17 December 2009 14:41 Go to next message
Nikita Missing nameFriend
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 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:OCL to generate EMF behaviour
Next Topic:EMF Performance - Loading, Saving, In-Memory
Goto Forum:
  


Current Time: Tue Apr 23 06:31:38 GMT 2024

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

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

Back to the top