Results 1 to 4 of 4

Thread: RESTful with Castor. Collection result is fine, but single result is very poluted

  1. #1
    Join Date
    Feb 2010
    Location
    Blumenau, Santa Catarina
    Posts
    15

    Unhappy RESTful with Castor. Collection result is fine, but single result is very poluted

    I'm using the Spring Roo and generated an application. I want to have on it RESTful services. I don't know if i need to implement or if spring already do this for me.

    I followed the links:
    http://static.springsource.org/sprin...l/ch18s02.html

    If i go to http://localhost:8080/geoLocationApp/address.xml the xml responsed is very good, with only "address" objects inside the list. That's ok.

    But if I want to get only a object, I do the url:
    http://localhost:8080/geoLocationApp/address/1.xml

    The result is very big, with a lot of objects I don't want. I don't know if I need to customize my own marshaller or if the CastorMarshaller of spring 3 would do that.

    Here is the example of the result of the URL http://localhost:8080/geoLocationApp/address.xml;
    Code:
    <array-list>
    −
    <Address xsi:type="Address">
    <ident>1</ident>
    <descricao>Evil address.</descricao>
    <version>0</version>
    </Address>
    −
    <Address xsi:type="Address">
    <ident>2</ident>
    <descricao>Rua Barroso.</descricao>
    <version>0</version>
    </Address>
    </array-list>
    Here is the example of the url http://localhost:8080/geoLocationApp/address/2.xml. It's Very poluted:

    Code:
    <bean-property-binding-result field-error-count="0" global-error-count="0" error-count="0">
    −
    <property-accessor auto-grow-nested-paths="true" extract-old-value-for-editor="true" xsi:type="java:org.springframework.beans.BeanWrapperImpl">
    −
    <root-instance xsi:type="Address">
    <ident>2</ident>
    </root-instance>
    <nested-path/>
    −
    <wrapped-instance xsi:type="Address">
    <ident>2</ident>
    </wrapped-instance>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>id</display-name>
    <name>id</name>
    <short-description>id</short-description>
    </property-descriptors>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>class</display-name>
    <name>class</name>
    <short-description>class</short-description>
    </property-descriptors>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>descricao</display-name>
    <name>descricao</name>
    <short-description>descricao</short-description>
    </property-descriptors>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>version</display-name>
    <name>version</name>
    <short-description>version</short-description>
    </property-descriptors>
    <conversion-service xsi:type="java:org.springframework.format.support.FormattingConversionService"/>
    </property-accessor>
    −
    <property-editor-registry auto-grow-nested-paths="true" extract-old-value-for-editor="true" xsi:type="java:org.springframework.beans.BeanWrapperImpl">
    −
    <root-instance xsi:type="Address">
    <ident>2</ident>
    </root-instance>
    <nested-path/>
    −
    <wrapped-instance xsi:type="Address">
    <ident>2</ident>
    </wrapped-instance>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>id</display-name>
    <name>id</name>
    <short-description>id</short-description>
    </property-descriptors>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>class</display-name>
    <name>class</name>
    <short-description>class</short-description>
    </property-descriptors>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>descricao</display-name>
    <name>descricao</name>
    <short-description>descricao</short-description>
    </property-descriptors>
    −
    <property-descriptors bound="false" constrained="false" expert="false" hidden="false" preferred="false" xsi:type="java:org.springframework.beans.GenericTypeAwarePropertyDescriptor">
    <display-name>version</display-name>
    <name>version</name>
    <short-description>version</short-description>
    </property-descriptors>
    <conversion-service xsi:type="java:org.springframework.format.support.FormattingConversionService"/>
    </property-editor-registry>
    −
    <model xsi:type="java:org.exolab.castor.mapping.MapItem">
    −
    <key xsi:type="java:java.lang.String">
    org.springframework.validation.BindingResult.address
    </key>
    </model>
    −
    <model xsi:type="java:org.exolab.castor.mapping.MapItem">
    <key xsi:type="java:java.lang.String">address</key>
    −
    <value xsi:type="Address">
    <ident>2</ident>
    </value>
    </model>
    <message-codes-resolver xsi:type="java:org.springframework.validation.DefaultMessageCodesResolver"/>
    −
    <target xsi:type="Address">
    <ident>2</ident>
    </target>
    <nested-path/>
    <object-name>address</object-name>
    </bean-property-binding-result>
    And My contentNegotiationResolver:
    Code:
    <bean
    		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    		<property name="mediaTypes">
    			<map>
    				<entry key="json" value="application/json" />
    				<entry key="xml" value="application/xml" />
    
    			</map>
    		</property>
    		<property name="defaultViews">
    			<list>
    				<bean
    					class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
    			
    				<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
    					<constructor-arg>
    						<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
    							<property name="mappingLocation" value="classpath:mapping.xml" />							
    						</bean>
    					</constructor-arg>
    				</bean>
    
    			</list>
    		</property>
    		<property name="ignoreAcceptHeader" value="true" />
    	</bean>

  2. #2

    Default

    Hello,

    Did you find any solution for this? I am facing the same problem.

    Thanks,
    Shweta

  3. #3
    Join Date
    Feb 2010
    Location
    Blumenau, Santa Catarina
    Posts
    15

    Default

    I think so...
    I dont remember very well.. sorry.

    But, I think I've tried to customize mapping.xml file of castor.

  4. #4

    Default

    Thanks for your reply. Turned out I had the mapping.xml file configured correctly, but the mapping that I used in my code was incorrect. I was not supplying the correct class type to the object being marshalled. I changed that and it works perfectly now .

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •