caelum / vraptor

Simple Java Web MVC Framework

Home Page:http://vraptor.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DateTime problems after updating from vraptor 3.5.1 to 3.5.3

danilomunoz opened this issue · comments

I've just update my project from vraptor 3.5.1 to 3.5.3. I have the converter for joda DateTime, but now I'm receiving null in DateTime fields.

I looked at this change #548, but I could'n solve the problem.

May someone could give some idea how to solve this?

Thanks,

The problem is that your converter is not being called?

can you paste here the startup log of the server, with debug logs for VRaptor, please?

There are too many log, but I just filtered by "datetime". Does it helps?

22/11/2013 15:02:45,946 DEBUG [GuiceComponentRegistry] Binding class br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter to class br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter
22/11/2013 15:02:45,949 DEBUG [GuiceComponentRegistry] Binding class br.com.caelum.vraptor.converter.jodatime.DateTimeConverter to class br.com.caelum.vraptor.converter.jodatime.DateTimeConverter
22/11/2013 15:02:46,093 DEBUG [GuiceComponentRegistry] Binding class br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream to class br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream
22/11/2013 15:02:46,095 DEBUG [GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream to class br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream
22/11/2013 15:02:46,095 DEBUG [GuiceComponentRegistry] Binding interface com.thoughtworks.xstream.converters.SingleValueConverter to class br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream
22/11/2013 15:02:46,096 DEBUG [GuiceComponentRegistry] Binding interface com.thoughtworks.xstream.converters.ConverterMatcher to class br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream
22/11/2013 15:02:46,268 DEBUG [GuiceComponentRegistry] Binding class br.com.mycompany.appname.api.converter.DateTimeConverter to class br.com.mycompany.appname.api.converter.DateTimeConverter
22/11/2013 15:02:46,270 DEBUG [GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.appname.api.converter.DateTimeConverter to class br.com.mycompany.appname.api.converter.DateTimeConverter
22/11/2013 15:02:46,316 DEBUG [GuiceComponentRegistry] Binding class br.com.mycompany.appname.api.converter.ConverterInputDateTime to class br.com.mycompany.appname.api.converter.ConverterInputDateTime
22/11/2013 15:02:46,317 DEBUG [GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.appname.api.converter.ConverterInputDateTime to class br.com.mycompany.appname.api.converter.ConverterInputDateTime
22/11/2013 15:02:46,317 DEBUG [GuiceComponentRegistry] Ignoring binding of interface br.com.caelum.vraptor.Converter to class br.com.mycompany.appname.api.converter.ConverterInputDateTime
22/11/2013 15:02:46,435 DEBUG [ScopeLifecycleListener] Registering lifecycle listeners for br.com.mycompany.appname.api.converter.ConverterInputOutputDateTimeXstream
22/11/2013 15:02:46,460 DEBUG [ScopeLifecycleListener] Registering lifecycle listeners for br.com.mycompany.appname.api.converter.DateTimeConverter
22/11/2013 15:02:46,466 DEBUG [ScopeLifecycleListener] Registering lifecycle listeners for br.com.mycompany.appname.api.converter.ConverterInputDateTime
22/11/2013 15:02:46,485 DEBUG [ScopeLifecycleListener] Registering lifecycle listeners for br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter
22/11/2013 15:02:46,485 DEBUG [ScopeLifecycleListener] Registering lifecycle listeners for br.com.caelum.vraptor.converter.jodatime.DateTimeConverter
22/11/2013 15:02:46,724 DEBUG [DefaultConverters   ] bundled converter to be registered: class br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter
22/11/2013 15:02:46,724 DEBUG [DefaultConverters   ] bundled converter to be registered: class br.com.caelum.vraptor.converter.jodatime.DateTimeConverter
...
22/11/2013 15:02:46,931 DEBUG [ConverterHandler    ] Ignoring handling default converter class br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter
22/11/2013 15:02:46,931 DEBUG [ConverterHandler    ] Ignoring handling default converter class br.com.caelum.vraptor.converter.jodatime.DateTimeConverter

This is my converter:

@Convert(DateTime.class)
@ApplicationScoped
public class ConverterInputDateTime implements Converter<DateTime> {
    public ConverterInputDateTime(DateTimeConverter dateTimeConverter){
              ...
    }

    @Override
    public DateTime convert(String value, Class<? extends DateTime> arg1, ResourceBundle arg2) {
              ...
    }
}

Thanks,

[GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.appname.api.converter.DateTimeConverter to class br.com.mycompany.appname.api.converter.DateTimeConverter

GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.appname.api.converter.ConverterInputDateTime to class br.com.mycompany.appname.api.converter.ConverterInputDateTime

It seems that guice registry is ignoring your classes...

Can you debug this GuiceComponentRegistry and see why it is ignoring your class?

It's going directly to the else clause at GuiceComponentRegistry#deepRegister:119

        // try register named component
        if (component.isAnnotationPresent(Named.class)) {
            Named named = ((Class<?>) component).getAnnotation(Named.class);
            logger.debug("Binding {} to {} with @Named({})", new Object[] { required, component, named.value() });
            binder.bind(required).annotatedWith(named).to(component);
        } else if (!boundClasses.contains(required)) {
            logger.debug("Binding {} to {}", required, component);
            binder.bind(required).to(component);
            boundClasses.add(required);
        } else {
            logger.debug("Ignoring binding of {} to {}", required, component);
        }

Can you debug DefaultConverters#register and DefaultConverters#to to see if your classes are being registered and usable?

Sorry for the late, I was trying to collect as many data as I could.

Steps:

  1. tomcat starting
  2. debug
DefaultConverters#register(converterClass = br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter)
    classes.addFirst(converterClass);
  1. debug
DefaultConverters#register(converterClass = br.com.caelum.vraptor.converter.jodatime.DateTimeConverter)
    classes.addFirst(converterClass);
  1. Log:
DEBUG [GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.myapp.api.converter.ConverterInputOutputDateTimeXstream to class br.com.mycompany.myapp.api.converter.ConverterInputOutputDateTimeXstream
  1. Log:
DEBUG [GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.myapp.api.converter.DateTimeConverter to class br.com.mycompany.myapp.api.converter.DateTimeConverter
  1. Log:
DEBUG [GuiceComponentRegistry] Ignoring binding of class br.com.mycompany.myapp.api.converter.ConverterInputDateTime to class br.com.mycompany.myapp.api.converter.ConverterInputDateTime
  1. debug
DefaultConverters#register(converterClass = br.com.caelum.vraptor.converter.jodatime.DateTimeConverter)
    classes.addFirst(converterClass);
  1. debug
DefaultConverters#register(converterClass = br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter)
    classes.addFirst(converterClass);
  1. debug
DefaultConverters#register(converterClass = br.com.mycompany.myapp.api.converter.ConverterInputDateTime)
    classes.addFirst(converterClass);
  1. Posting json data
POST http://ip/myapp/xpto/add
Content-Type: application/json

{
    "br.com.xpto.model.MyModel": {
        "dateTime": "2013-11-22T12:00:00.000Z"
    }
}
  1. VRaptor receiving the model
@Post
@Path("add")
@Consumes
public void add (MyModel model) {
//model.dateTime = null
//another fields arrives OK
}

Thanks,

You are using @Consumes, so the converters are not used. Only the Deserializers.

The correct json is:

{
    "model": {
        "dateTime": "2013-11-22T12:00:00.000Z"
    }
}

since model is the parameter name.

this should work also:

{
   "dateTime": "2013-11-22T12:00:00.000Z"
}

This process always worked without problems ...

After doing more tests I discovered that the problem occurs when updating the xstream from 1.3.1 to 1.4.3 version. Using vraptor 3.5.3 + xstream 1.3.1, works fine. Using vraptor 3.5.3 + xstream 1.4.3, does not work properly!

So, this seems to be a xstream desserialization problem. What do you guys recommend for me now?

Thanks,

Can you sue vraptor 3.5.3 + xtream 1.3.1?

I think so! We're testing all the projects in order to check it.

And not urgently: what about the next versions? Any idea how we can
prevent or solve this issue?

Thanks for your time,

Em segunda-feira, 25 de novembro de 2013, Lucas Cavalcanti escreveu:

Can you sue vraptor 3.5.3 + xtream 1.3.1?


Reply to this email directly or view it on GitHubhttps://github.com//issues/585#issuecomment-29204457
.

Danilo Rosetto Muñoz
munozdanilo@gmail.com
http://br.linkedin.com/in/danilomunoz

We're moving to GSon for Json (de)serialization, so this should solve the issue.

Very nice! GSon seems to be very nice!

It's getting very complicate for us continue using xstream 1.3.1! It generated another erros ... :-(

So, we've tried looking for the problem into xstream code and the main differences are in AbstractReflectionConverter#doUnmarshal (second while reader.hasMoreChildren()). I can't identify if this issue is related to some vraptor xstream configuration or some xstream bug.

To reproduce this error you can:

  • Create a simple project
  • Add xstream 1.3.1
  • Test
  • Change to the xstream 1.4.x
  • Test

Resources:

Posted JSON:

{
    "myModel": {
        "dateTimeField": "10/30/2013"
    }
}

Controller:

@Post
@Consumes
public void jsonTest(MyModel myModel){
    //Check dateTimeField value
    // xstream 1.3.1: dateTimeField is filed and different of null
    // xstream 1.4.x: dateTimeField is null
}

Converter:

@Component
@ApplicationScoped
public class DateTimeXStreamConverter implements SingleValueConverter{
     //implementation
}

MyModel:

public class MyModel{
    private DateTime dateTimeField;

    //getter and setter
}

Thanks,

what errors?

We have a large product running with vraptor and we got spread errors along the java projects.
We decided to use a task force and move to GSON ... It's not easy, but we are doing.
Thanks,

Hi,

I think we can close this ticket. Today we are using vraptor 4 and everthing is working fine for us. And it seems there are no more issues related by other users related to this subject.

Regards,

Closing. Thanks @danilomunoz!