Unsupported media type 'text/html'

251 views
Skip to first unread message

RafaelViana

unread,
Feb 2, 2011, 7:25:51 AM2/2/11
to restfulie-java
Estou criando um controller Rest e ocorreu essa exception. Por quê?

br.com.caelum.restfulie.RestfulieException: Unsupported media type
'text/html'
at
br.com.caelum.restfulie.mediatype.MediaTypes.forContentType(MediaTypes.java:
27)
at
br.com.caelum.restfulie.http.apache.ApacheResponse.getResource(ApacheResponse.java:
59)
at
br.com.caelum.client.ClientTests.shouldBeAbleToPostASale(ClientTests.java:
41)
...

No servidor:

SalesController.java

@Resource
public class SalesController
{
@Post
@Consumes
@Path("/sales")
public void create(Sale sale)
{
System.out.println(sale);
}
}

@XStreamAlias("sale")
public class Sale
{
private Integer id;
private Double ammount;
private List<Item> items;
}

No cliente:

@Before
public void setUp() throws Exception
{
restfulie = Restfulie.custom();
restfulie.getMediaTypes().register(new
XmlMediaType().withTypes(Item.class, Sale.class));
}

@Test
public void shouldBeAbleToPostASale() throws Exception
{
Item item = new Item("pipa", 299.0);

Sale sale = new Sale();
sale.sellItem(item);

Response response = restfulie.at("http://localhost:8080/restfulie/
sales")
.accept("application/xml")
.as("application/xml")
.post(sale);

Sale savedSale = response.getResource();
assertNotSame(sale, savedSale);
}

Lucas Cavalcanti

unread,
Feb 2, 2011, 7:33:19 AM2/2/11
to restful...@googlegroups.com
The create method does not specify a result, so VRaptor will use the default one: a jsp and therefore text/html

you must set the result (receiving a Result on the constructor):

result.use(representation()).from(sale).serialize();

or adding a created response linking to another URI, that generates a xml response:

result.use(status()).created("/sales/" + sale.getId());

[]'s

RafaelViana

unread,
Feb 2, 2011, 7:45:37 AM2/2/11
to restfulie-java
I changed the controller but the still happens

@Resource
public class SalesController {

private final Result result;

public SalesController(Result result)
{
this.result = result;
}

@Post
@Consumes
@Path("/sales")
public void create(Sale sale)
{
System.out.println(sale);
result.use(representation()).from(sale).serialize();
}
}

On 2 fev, 10:33, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> The create method does not specify a result, so VRaptor will use the default
> one: a jsp and therefore text/html
>
> you must set the result (receiving a Result on the constructor):
>
> result.use(representation()).from(sale).serialize();
>
> or adding a created response linking to another URI, that generates a xml
> response:
>
> result.use(status()).created("/sales/" + sale.getId());
>
> []'s
>

Lucas Cavalcanti

unread,
Feb 2, 2011, 7:51:06 AM2/2/11
to restful...@googlegroups.com
are you using beta4 or the latest version from repository?

RafaelViana

unread,
Feb 2, 2011, 8:03:51 AM2/2/11
to restfulie-java
I'm using the beta5-SNAPSHOT.

On 2 fev, 10:51, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> are you using beta4 or the latest version from repository?
>

RafaelViana

unread,
Feb 2, 2011, 8:41:58 AM2/2/11
to restfulie-java
Can you try to run the test with these classes?

Lucas Cavalcanti

unread,
Feb 2, 2011, 9:00:21 AM2/2/11
to restful...@googlegroups.com
try @Consumes("application/xml")

Guilherme Silveira

unread,
Feb 2, 2011, 10:02:53 AM2/2/11
to restfulie-java
Just a small note:

having("application/xml") is an alias for both:

> .accept("application/xml")
> .as("application/xml")

Let us know about the @Consumes.

Regards


Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

RafaelViana

unread,
Feb 2, 2011, 10:18:08 AM2/2/11
to restfulie-java
It didn't work with @Consumes("application/xml")

I found the error. I think it's a bug.

Sale.java (with the collection)

@XStreamAlias("sale")
public class Sale
{
private Integer id;
private Double ammount = new Double(0.0);
private List<Item> items = new ArrayList<Item>();

public void sellItem(Item item)
{
items.add(item);
ammount += item.getPrice();
}
}

Output: br.com.caelum.restfulie.RestfulieException: Unsupported media
type 'text/html'

--------------------

Sale.java (without the collection)

@XStreamAlias("sale")
public class Sale
{
private Integer id;
private Double ammount = new Double(0.0);

public void sellItem(Item item)
{
ammount += item.getPrice();
}
}

The test runs ok.

Please try this to confirm if is it a bug or not?

On 2 fev, 12:00, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> try @Consumes("application/xml")
>

Lucas Cavalcanti

unread,
Feb 2, 2011, 11:05:28 AM2/2/11
to restful...@googlegroups.com
try to send a request manually (e.g using Poster FF extension) and see what is the html response
remember to set the headers accordingly

RafaelViana

unread,
Feb 2, 2011, 11:19:36 AM2/2/11
to restfulie-java
What headers do I need to set?

On 2 fev, 14:05, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> try to send a request manually (e.g using Poster FF extension) and see what
> is the html response
> remember to set the headers accordingly
>

Lucas Cavalcanti

unread,
Feb 2, 2011, 11:28:03 AM2/2/11
to restful...@googlegroups.com
Content-Type: application/xml
Accept: application/xml

RafaelViana

unread,
Feb 2, 2011, 12:17:39 PM2/2/11
to restfulie-java
I set the headers and made the test ( I don't if I did it right ).

Response Status 500.

Headers:
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 7050

The restfulie get this Content-Type (text/html) in the
ApacheResponde.getResource() and in the MediaTypes.forContentType()
throws the Exception.

Did you try to run a test with collections?

On 2 fev, 14:28, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> Content-Type: application/xml
> Accept: application/xml
>

Guilherme Silveira

unread,
Feb 2, 2011, 12:42:46 PM2/2/11
to restfulie-java
Hi Rafael, can you try the following?

@XStreamAlias("sale")
public class Sale
{
private Integer id;
private Double ammount = new Double(0.0);

private List<Item> items;

public void sellItem(Item item)
{
getItems().add(item);
ammount += item.getPrice();
}
private List<Item> getItems() {
if(items==null) items = new ArrayList<Item>();
return items;
}
}

Can you also try debugging or logging (sysouting is fine) to check
that the logic method has been invoked?


Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

Lucas Cavalcanti

unread,
Feb 2, 2011, 12:53:26 PM2/2/11
to restful...@googlegroups.com
what is the exception on the 500 error?

RafaelViana

unread,
Feb 2, 2011, 1:03:52 PM2/2/11
to restfulie-java
The error happens because the collection. It's strange.

Using the Sale with collection ( even using your implementation ) the
content type arrives to getResponse() in ApacheResponse as text/html.
However, using the sale without the collection the content type
arrives as application/xml.

This test was made changing only the model, without changes in the
controller or test code.

On 2 fev, 15:42, Guilherme Silveira <guilherme.silve...@caelum.com.br>
wrote:
> Hi Rafael, can you try the following?
>
> @XStreamAlias("sale")
> public class Sale
> {
>        private Integer id;
>        private Double ammount = new Double(0.0);
>        private List<Item> items;
>
>        public void sellItem(Item item)
>        {
>                getItems().add(item);
>                ammount += item.getPrice();
>        }
>        private List<Item> getItems() {
>            if(items==null) items = new ArrayList<Item>();
>            return items;
>        }
>
> }
>
> Can you also try debugging or logging (sysouting is fine) to check
> that the logic method has been invoked?
>
> Guilherme Silveira
> Caelum | Ensino e Inovaçãohttp://www.caelum.com.br/

Guilherme Silveira

unread,
Feb 2, 2011, 1:09:51 PM2/2/11
to restful...@googlegroups.com

Hi rafael, did you try the code I sent?
It might be due to xstream not using reflection to instantiating your model.then some collateral effect is throwing the error...

2011. 2. 2. 오후 4:03에 "RafaelViana" <rfl....@gmail.com>님이 작성:



The error happens because the collection. It's strange.

Using the Sale with collection ( even using your implementation ) the
content type arrives to getResponse() in ApacheResponse as text/html.
However, using the sale without the collection the content type
arrives as application/xml.

This test was made changing only the model, without changes in the
controller or test code.

On 2 fev, 15:42, Guilherme Silveira <guilherme.silve...@caelum.com.br>
wrote:

> Hi Rafael, can you try the following?
>
> @XStreamAlias("sale")
> public class Sale
> {

>        p...

> Caelum | Ensino e Inovaçãohttp://www.caelum.com.br/

>
> On Wed, Feb 2, 2011 at 3:17 PM, RafaelViana <rfl.vi...@gmail.com> wrote:

> > I set the headers a...

RafaelViana

unread,
Feb 2, 2011, 1:25:07 PM2/2/11
to restfulie-java
Yes, I tried.
With your code the content type arrive as text/xml.

Then when I remove the collection:

@XStreamAlias("sale")
public class Sale
{
private Integer id;
private Double ammount = new Double(0.0);

public void sellItem(Item item){ ammount += item.getPrice(); }
}

The content type arrives as application/xml and it works.

On 2 fev, 16:09, Guilherme Silveira <guilherme.silve...@caelum.com.br>
wrote:
> Hi rafael, did you try the code I sent?
> It might be due to xstream not using reflection to instantiating your
> model.then some collateral effect is throwing the error...
>
> 2011. 2. 2. 오후 4:03에 "RafaelViana" <rfl.vi...@gmail.com>님이 작성:

Guilherme Silveira

unread,
Feb 2, 2011, 1:39:35 PM2/2/11
to restful...@googlegroups.com
Hi Rafael,

text/xml or text/html?

Regards

Guilherme Silveira
Caelum | Ensino e Inovação

http://www.caelum.com.br/

RafaelViana

unread,
Feb 2, 2011, 2:04:37 PM2/2/11
to restfulie-java
text/html

On 2 fev, 16:39, Guilherme Silveira <guilherme.silve...@caelum.com.br>
wrote:
> Hi Rafael,
>
> text/xml or text/html?
>
> Regards
>
> Guilherme Silveira
> Caelum | Ensino e Inovaçãohttp://www.caelum.com.br/
>

Lucas Cavalcanti

unread,
Feb 2, 2011, 3:35:42 PM2/2/11
to restful...@googlegroups.com
what is the exception?

RafaelViana

unread,
Feb 2, 2011, 4:22:46 PM2/2/11
to restfulie-java
Premature end of file

On 2 fev, 18:35, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> what is the exception?
>

Guilherme Silveira

unread,
Feb 3, 2011, 9:34:18 AM2/3/11
to restful...@googlegroups.com

Hi Rafael,
Can you extract the example in a simple project so we can run the same code?
Regards

2011. 2. 2. 오후 7:22에 "RafaelViana" <rfl....@gmail.com>님이 작성:



Premature end of file


On 2 fev, 18:35, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> what is the exception?
>

> On Wed, Feb 2, 2011 at 5:04 PM, RafaelViana <rfl.vi...@gmail.com> wrote:
> > text/html
>

> > On 2 ...

RafaelViana

unread,
Feb 3, 2011, 11:45:25 AM2/3/11
to restfulie-java
Hi Guilherme,

Done!

https://github.com/RafaelRViana/restfulie-collection-error

On 3 fev, 12:34, Guilherme Silveira <guilherme.silve...@caelum.com.br>
wrote:
> Hi Rafael,
> Can you extract the example in a simple project so we can run the same code?
> Regards
>
> 2011. 2. 2. 오후 7:22에 "RafaelViana" <rfl.vi...@gmail.com>님이 작성:

RafaelViana

unread,
Feb 3, 2011, 2:04:34 PM2/3/11
to restfulie-java
Hi Guilherme,

Did you get to simulate the error?

RafaelViana

unread,
Feb 5, 2011, 10:20:50 AM2/5/11
to restfulie-java
Hi Guilherme and Lucas,

I tried it again. Now, I looked at the server log and saw this:

05/02/2011 13:13:03 org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet default threw exception
com.thoughtworks.xstream.converters.ConversionException: item : item :
item : item
---- Debugging information ----
message : item : item
cause-exception :
com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : item : item
class : br.com.caelum.example.model.Sale
required-type : java.util.ArrayList
path : /sale/items/item

It throws an Exception. So, the response was text/html. (You are right
Guilherme).

I found a post in GUJ solving this error.
http://www.guj.com.br/java/52332-converter-um-resultado-do-xtream-para-varios-objetos

It's needed to configure the alias to work with collections.

I found a method inside XmlMediaType.java.

/**
* Allows xstream further configuration.
*/
protected void configure(XStream xstream)
{
}

Is it working? Can I add the alias using this method? Where do I need
to call?
If not. Monday, I'll try to implement it.

Lucas Cavalcanti

unread,
Feb 5, 2011, 11:39:42 AM2/5/11
to restful...@googlegroups.com
have you tried to put @XStreamAlias("item") on item class?


2011/2/5 RafaelViana <rfl....@gmail.com>

RafaelViana

unread,
Feb 6, 2011, 6:36:16 PM2/6/11
to restfulie-java
I made some tests. I tried to serialize/dedeserialize manually the
object sale.

E.g:
XStream xstream = new XStream();
xstream.alias("item", Item.class);
xstream.alias("sale", Sale.class);

Sale teste = new Sale();
teste.sellItem(new Item("pipa", 20.0));
String pipa = xstream.toXML(teste);
Sale result = (Sale) xstream.fromXML(pipa);

In the server (I passed the XStream to XMLMediaType) and client side.
It works well and the result is the same.

Then, I think the problem is somewhere in the integration with
Vraptor.
I noticed that none line in my post method is called. For example:

This is the method used to post:

@Post
@Consumes
@Path("/sales")
public void create(Sale sale)
{

System.out.println("***************************************************************");
result.use(representation()).from(sale).serialize();
}

When, I call it using Restfulie. The exception occurs before call the
sysout. So, it occurs before the serialize.
Watching carefully in the log:

21:31:53,968 DEBUG [LazyInterceptorHandler] Invoking interceptor
DeserializingInterceptor
21:31:53,968 DEBUG [VRaptorApplicationContext] Cache miss for
interface br.com.caelum.vraptor.deserialization.XMLDeserializer
21:31:54,136 DEBUG [ParanamerNameProvider] Found parameter names with
paranamer for SalesController.create(Sale) as [sale]
06/02/2011 21:31:54 org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet default threw exception
com.thoughtworks.xstream.converters.ConversionException: item : item :
item : item
---- Debugging information ----
message : item : item
cause-exception :
com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : item : item
class : br.com.caelum.example.model.Sale
required-type : java.util.ArrayList
path : /sale/items/item

The error happens after this: 21:31:54,136 DEBUG
[ParanamerNameProvider] Found parameter names with paranamer for
SalesController.create(Sale) as [sale]

Can this error happens during the creation with paranamer?

On 5 fev, 14:39, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> have you tried to put @XStreamAlias("item") on item class?
>
> 2011/2/5 RafaelViana <rfl.vi...@gmail.com>
>
> > Hi Guilherme and Lucas,
>
> > I tried it again. Now, I looked at the server log and saw this:
>
> > 05/02/2011 13:13:03 org.apache.catalina.core.StandardWrapperValve
> > invoke
> > SEVERE: Servlet.service() for servlet default threw exception
> > com.thoughtworks.xstream.converters.ConversionException: item : item :
> > item : item
> > ---- Debugging information ----
> > message : item : item
> > cause-exception :
> > com.thoughtworks.xstream.mapper.CannotResolveClassException
> > cause-message : item : item
> > class : br.com.caelum.example.model.Sale
> > required-type : java.util.ArrayList
> > path : /sale/items/item
>
> > It throws an Exception. So, the response was text/html. (You are right
> > Guilherme).
>
> > I found a post in GUJ solving this error.
>
> >http://www.guj.com.br/java/52332-converter-um-resultado-do-xtream-par...

Lucas Cavalcanti

unread,
Feb 7, 2011, 10:31:38 AM2/7/11
to restful...@googlegroups.com
I sent you a pull request... 

the problem was that VRaptor adds only the first class (Sale) on the XStream by default.

If you want to add more classes, you need to override the Deserializer and configure it.

[]'s

2011/2/6 RafaelViana <rfl....@gmail.com>

RafaelViana

unread,
Feb 7, 2011, 11:52:44 AM2/7/11
to restfulie-java
Thanks. It worked.

Can I "bother" you with just one more question?

The sale goes to the server with the amount and items list filled.
However, when I sent the result back to the client:
result.use(representation()).from(sale).serialize();

The resource comes with the amount filled but the items list is empty.
What error could be this?

On 7 fev, 13:31, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> I sent you a pull request...
>
> the problem was that VRaptor adds only the first class (Sale) on the XStream
> by default.
>
> If you want to add more classes, you need to override the Deserializer and
> configure it.
>
> []'s
>
> 2011/2/6 RafaelViana <rfl.vi...@gmail.com>

Lucas Cavalcanti

unread,
Feb 7, 2011, 12:42:52 PM2/7/11
to restful...@googlegroups.com
you must add the items explicitly:

result.use(representation()).from(sale).include("items").serialize();

RafaelViana

unread,
Feb 7, 2011, 1:12:11 PM2/7/11
to restfulie-java
Thanks.

Every different object needs to be included? Or just collections?
For example, considered I'm using tiny types I also need to include
them?

On 7 fev, 15:42, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> you must add the items explicitly:
>
> result.use(representation()).from(sale).include("items").serialize();
>

Lucas Cavalcanti

unread,
Feb 7, 2011, 1:52:11 PM2/7/11
to restful...@googlegroups.com
any object that is not primitive (numbers, dates and String)

although we could find a way to easily identify the tiny-types, suggestions? 

RafaelViana

unread,
Feb 7, 2011, 4:01:41 PM2/7/11
to restfulie-java
I took a brief look at VRaptor source. from() method calls
preConfigure. It excludes the non-primitive types.
And includes() excludes the field from the list allowing them to be
serialized.

Some doubts to understand better:

1) I saw that XStream has default converters for some types. VRaptor
excludes non-primitive types because XStream can't handle with them?
2) The XStream has a converter for java.util.ArrayList because of this
the list came filled. Why the method isPrimitive() don't support it?
3) I tried to serialize a tiny type and it comes null. To serialize it
do I need a converter? So, even I include it to the list. It will need
a converter.

My Ideas:

I thought to use a annotation like this:
@IncludedInSerialization(converter=AnyConverter.class)
private TinyType any;

And in the excludeNonPrimitiveFields() method don't exclude the fields
that use this annotation. (there is a tradeoff is it better annotate
or configure programatically?)
I don't know if I could get this converter to register it to XStream.

So, the converters can me registered to XStream in the
CustomXStreamXMLDeserializer.
Or could be used CoC (Convention Over Configuration). Finding every
class that implements Converter and register it to the XStream.

If you agree I'll implement it tonight.

On 7 fev, 16:52, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> any object that is not primitive (numbers, dates and String)
>
> although we could find a way to easily identify the tiny-types,
> suggestions?
>

RafaelViana

unread,
Feb 7, 2011, 4:04:39 PM2/7/11
to restfulie-java
Just to complement.

If annotate every field the class get dirty. It would be better by
default serialize every field. And ommit only the fields annotated
with @XStreamOmmitField.

Lucas Cavalcanti

unread,
Feb 7, 2011, 4:26:29 PM2/7/11
to restful...@googlegroups.com
We chose to exclude non-primitives to avoid serialization cycles (that can lead to infinite loops).

but if you use only xml, you can use:

result.use(xml()).from(object).recursive().serialize();

so no fields are excluded.
Maybe implement the recursive method for all serializations would be the way around (we cannot change
existing behavior, because people rely on it)

> 3) I tried to serialize a tiny type and it comes null. To serialize it
> do I need a converter? So, even I include it to the list. It will need
> a converter.
it should not be happening, show me the code please?

I liked the idea of registering every @Component that implements the xstream Converter interface,
you could implement it too (or open an issue so we will).

Thank you for the suggestions =)

[]'s
Lucas

RafaelViana

unread,
Feb 7, 2011, 5:08:59 PM2/7/11
to restfulie-java
I downloaded the VRaptor source. I'll implement it.

I had a problem serializing a persisted object:
Caused by:
com.thoughtworks.xstream.mapper.CannotResolveClassException:
persistentBag : persistentBag

Do you have a default solution?
I saw in the XStream mailing list a PersistentBagConverter that
converts the PersistentBags into ArrayList. Is this the best
solution?
Can VRaptor has a default converter for this?
I can provide it too.

On 7 fev, 19:26, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> We chose to exclude non-primitives to avoid serialization cycles (that can
> lead to infinite loops).
>
> but if you use only xml, you can use:
>
> result.use(xml()).from(object).recursive().serialize();
>
> so no fields are excluded.
> Maybe implement the recursive method for all serializations would be the way
> around (we cannot change
> existing behavior, because people rely on it)
>
> > 3) I tried to serialize a tiny type and it comes null. To serialize it
> > do I need a converter? So, even I include it to the list. It will need
> > a converter.
>
> it should not be happening, show me the code please?
>
> I liked the idea of registering every @Component that implements the xstream
> Converter interface,
> you could implement it too (or open an issue so we will).
>
> Thank you for the suggestions =)
>
> []'s
> Lucas
>
> ...
>
> mais »

Lucas Cavalcanti

unread,
Feb 7, 2011, 5:24:23 PM2/7/11
to restful...@googlegroups.com
Did you use Arrays.asList on the tests? if so you can use new ArrayList(Arrays.asList(...));

[]'s

RafaelViana

unread,
Feb 8, 2011, 5:04:43 AM2/8/11
to restfulie-java
I started to implement it.

As I've never used reflection, I read VRaptor's classes to understand
how VRaptor does this scanning ( to maintain a pattern ).
I saw you use the scannotation lib to find annotated classes in
classpath. I didn't find any class that reads classes in classpath.
Has it?

Considered I read the whole classpath finding classes that implements
XStreamConverter. Wouldn't it be slow than find a class using an
annotation?

In your opinion, what is the best:

1) Annotate converters with @XStreamConverter. So, I can find the
converters using scannotation. It seems easier and faster.
2) Scan the classpath, loading each class to find if it implements the
XStreamConverter. It is cleaner because users don't need to annotate
the converter, but seems slower because the need to load each class.

On 7 fev, 19:26, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> We chose to exclude non-primitives to avoid serialization cycles (that can
> lead to infinite loops).
>
> but if you use only xml, you can use:
>
> result.use(xml()).from(object).recursive().serialize();
>
> so no fields are excluded.
> Maybe implement the recursive method for all serializations would be the way
> around (we cannot change
> existing behavior, because people rely on it)
>
> > 3) I tried to serialize a tiny type and it comes null. To serialize it
> > do I need a converter? So, even I include it to the list. It will need
> > a converter.
>
> it should not be happening, show me the code please?
>
> I liked the idea of registering every @Component that implements the xstream
> Converter interface,
> you could implement it too (or open an issue so we will).
>
> Thank you for the suggestions =)
>
> []'s
> Lucas
>
> ...
>
> mais »

RafaelViana

unread,
Feb 8, 2011, 7:26:07 AM2/8/11
to restfulie-java
I'm trying to solve this exception all the morning, but without
success.

The XML comes to the client, with the persistenceBag:

<itens__vendidos class="persistentBag">
<initialized>true</initialized>
<cachedSize>-1</cachedSize>
<dirty>false</dirty>
<storedSnapshot class="list">
<itens__vendidos>
<id>16</id>
<descricao>pipa</descricao>
<valorItem>
<valor>200.0</valor>
</valorItem>
<quantidade>
<valor>1</valor>
</quantidade>
<valorTotalDoItem>
<valor>200.0</valor>
</valorTotalDoItem>
<isCancelado>false</isCancelado>
</itens__vendidos>
</storedSnapshot>
<bag>
<itens__vendidos>
<id>16</id>
<descricao>pipa</descricao>
<valorItem>
<valor>200.0</valor>
</valorItem>
<quantidade>
<valor>1</valor>
</quantidade>
<valorTotalDoItem>
<valor>200.0</valor>
</valorTotalDoItem>
<isCancelado>false</isCancelado>
</itens__vendidos>
</bag>
</itens__vendidos>

Do I need the converter in client side, server side or both?

On 7 fev, 20:24, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> Did you use Arrays.asList on the tests? if so you can use new
> ArrayList(Arrays.asList(...));
>
> []'s
>
> ...
>
> mais »

RafaelViana

unread,
Feb 8, 2011, 7:47:33 AM2/8/11
to restfulie-java
I'm making some tests. I put a converter inside the
XStreamSerializer.

xstream.registerConverter(new
CollectionConverter(xstream.getMapper())
{ public boolean canConvert(Class clazz) { return
PersistentBag.class == clazz; } });

So, the serialized was it:

<itens__vendidos class="persistentBag">
<itens__vendidos>
<id>22</id>
<descricao>pipa</descricao>
<valorItem>
<valor>200.0</valor>
</valorItem>
<quantidade>
<valor>1</valor>
</quantidade>
<valorTotalDoItem>
<valor>200.0</valor>
</valorTotalDoItem>
<isCancelado>false</isCancelado>
</itens__vendidos>
</itens__vendidos>
</venda>

But the exception remains, how could I remove the
class="persistentBag"?
> ...
>
> mais »

Lucas Cavalcanti

unread,
Feb 8, 2011, 8:35:21 AM2/8/11
to restful...@googlegroups.com
Hi Rafael,

You don't need to scan the classpath looking for annotations, VRaptor already does that.
If all xstream Converter implementations are annotated with @Component, you can just receive
on the XStreamXMLDeserializer a List<Converter>, on the constructor, and it will work. Careful
to import xstream converter, not vraptor's.

the better way to deal with persistentBag (all collections actually) is to wrap it in an ArrayList
before serializing.

[]'s
Lucas

RafaelViana

unread,
Feb 8, 2011, 2:00:14 PM2/8/11
to restfulie-java
Sent the pull request with the implementation.

On 8 fev, 11:35, Lucas Cavalcanti <lucasmrtu...@gmail.com> wrote:
> Hi Rafael,
>
> You don't need to scan the classpath looking for annotations, VRaptor
> already does that.
> If all xstream Converter implementations are annotated with @Component, you
> can just receive
> on the XStreamXMLDeserializer a List<Converter>, on the constructor, and it
> will work. Careful
> to import xstream converter, not vraptor's.
>
> the better way to deal with persistentBag (all collections actually) is to
> wrap it in an ArrayList
> before serializing.
>
> []'s
> Lucas
>
> ...
>
> mais »
Reply all
Reply to author
Forward
0 new messages