VAST XML Mapping needs Attribute definition?

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

VAST XML Mapping needs Attribute definition?

Postby jtuchel » Mon Oct 12, 2009 6:10 am

Hi there,

it seems the XML mapping framework requires a class to define all mapped instance variables in the public interface.
If you have an attribute mapping like this:

<AttributeMapping ClassAttribute="firstname">
<Attribute>firstName</Attribute>
</AttributeMapping>

The instance variable of the mapped class will remain nil when deserialising as long as there is no attribute definition for the variable.

I'd consider this a bug, because I see no reason for an attribute definition in here at all, UNLESS there also is an InstVarMapping hidden somewhere in the framework...?
A simple approach to improving this is probably to first check for an attribute and after that a setter method of the same name, thus the existence of an attribute in the PI of a class would be respected, but if there is none, the instVar would be filled nevertheless.
I know I can add information on getters and setters in a mapping spec, but for cases in which getter and setter simply are the same as the instvar name (I guess 87 % of the time this is the case) this seems like overhead to me...

Ah, I've tried in VAST 8.0 and 7.5.

cu

Joachim
jtuchel
[|]
 
Posts: 245
Joined: Fri Oct 05, 2007 1:05 am
Location: Ludwigsburg, Germany

Re: VAST XML Mapping needs Attribute definition?

Postby Diane Engles » Fri Oct 16, 2009 11:27 am

Hi Joachim,

The following applies to deserialization with AbtXmlMappingParser using a schema. The basic mechanism for finding selectors to invoke when deserializing will work without a mapping spec as long as the element to be deserialized is a simple type (xsd:string, xsd:float, xsd:boolean, xsd:int, etc.) and the getter method in the Smalltalk class exactly matches (case-sensitive) the element tag.

So in your example, if the data xml is as follows:

<Person>
<firstName>Bill</firstName>
<lastName>Smith</lastName>
</Person>

there must be an accessor method in the Smalltalk class Person>>firstName for deserialization to occur without a mapping spec.

Alternatively, you can change the data xml so that the element tag name is the same as the existing accessor:

<Person>
<firstname>Bill</firstname>
<lastName>Smith</lastName>
</Person>

Check out the methods AbtXmlMappedObject>>setSelectorFor:attributes:mapping: and AbtXmlMappedObject>>defaultSetSelectorFor:

If a schema isn't in place, the elements will deserialize as strings.

Hope that helps.
Instantiations Smalltalk Support
diane@instantiations.com
Diane Engles
Moderator
 
Posts: 66
Joined: Mon Oct 16, 2006 2:40 pm

Re: VAST XML Mapping needs Attribute definition?

Postby jtuchel » Tue Oct 27, 2009 3:00 am

Diane,

so what exactly do I need to do if my instVar is named shippingAddress, but the xml tag is ShippingAddress? Is the only solution to provide getter and setter names in the mapping spec?

My picture is that a schema is only about the form of the xml file, and the mapping is about the smalltalk part...

Kind Regards,


Joachim
jtuchel
[|]
 
Posts: 245
Joined: Fri Oct 05, 2007 1:05 am
Location: Ludwigsburg, Germany


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest