Skip to main content



      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 09:41 Go to next message
Eclipse UserFriend
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 09:43] by Moderator

Re: Outputting an EObject to a string for debugging or logging [message #504192 is a reply to message #504169] Thu, 17 December 2009 10:58 Go to previous message
Eclipse UserFriend
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
Previous Topic:OCL to generate EMF behaviour
Next Topic:EMF Performance - Loading, Saving, In-Memory
Goto Forum:
  


Current Time: Thu Jul 24 00:09:08 EDT 2025

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

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

Back to the top