Code Monkey home page Code Monkey logo

Comments (10)

maybeec avatar maybeec commented on July 29, 2024 1

Ah ok, this is a maping problem, you are right, did not get that.
Please add the required types to be mapped by reference in the dozer-mapping.xml file in your devon project like this:

    <copy-by-references>
      
      <copy-by-reference>java.lang.Long</copy-by-reference>
      <copy-by-reference>java.lang.Integer</copy-by-reference>
      <copy-by-reference>java.lang.Number</copy-by-reference>
      <copy-by-reference>java.util.Currency</copy-by-reference>
      <copy-by-reference>java.time.LocalTime</copy-by-reference>
      <copy-by-reference>java.time.ZonedDateTime</copy-by-reference>
      
      <!--
      <copy-by-reference>javax.money.MonetaryAmount</copy-by-reference>
      <copy-by-reference>org.javamoney.moneta.Money</copy-by-reference>
       -->
    </copy-by-references>

from devon4j.

jconcavi avatar jconcavi commented on July 29, 2024 1

Hi @hohwille and @maybeec :

I test the solution on a devon4j application, and my steps done are:

Modify the dozer-mapping.xml as follows:

      <copy-by-reference>java.time.LocalDate</copy-by-reference>
      <copy-by-reference>java.time.LocalDateTime</copy-by-reference>
      <copy-by-reference>java.time.LocalTime</copy-by-reference>
      <copy-by-reference>java.time.ZonedDateTime</copy-by-reference>
      <copy-by-reference>java.time.Instant</copy-by-reference>

After using the cobigen tool, based on the entity:

@Entity
@Table(name = "DateTimeConversion")
public class DateTimeConversionEntity extends ApplicationPersistenceEntity implements DateTimeConversion {

	private LocalDate localDate;

	private LocalTime localTime;

	private LocalDateTime localDateTime;

	private ZonedDateTime zonedDateTime;

	private Instant instant;

	private static final long serialVersionUID = 1L;

I modify the Eto to have all the attribute as String, and don't implements the interface:

public class DateTimeConversionEto extends AbstractEto {

	private static final long serialVersionUID = 1L;

	private String localDate;

	private String localTime;

	private String localDateTime;

	private String zonedDateTime;

	private String instant;

So when I retry the object via rest this will be the response:

{"dateTimeConversion":
    {"id":1,
     "modificationCounter":0,
     "localDate":"2019-01-29",
     "localTime":"08:31:15",
     "localDateTime":"2019-01-29T08:31:15",
     "zonedDateTime":"2019-01-29T08:31:15+01:00[Europe/Paris]",
     "instant":"2019-01-29T07:31:15Z"}
}

Please proceed to add the required dozer into the archetype, and if is possible document all the steps done / change cobigen to be aligned with this scenario.

from devon4j.

maybeec avatar maybeec commented on July 29, 2024 1

@jconcavi why do you change the Eto date time types to string already in logic layer?
For me the logical way would be to do the date time to string conversion at the service layer by jaxrs more or less automatically or by writing your own serializers/deserializers.

from devon4j.

hohwille avatar hohwille commented on July 29, 2024 1

https://github.com/FasterXML/jackson-modules-java8

from devon4j.

maybeec avatar maybeec commented on July 29, 2024

@jdiazgon seems to be an CobiGen only issue, could you try to reproduce it?
If so, you could move this ticket to the CobiGen repo. Moving tickets should be implemented by GitHub now.

from devon4j.

jconcavi avatar jconcavi commented on July 29, 2024

Hi @maybeec :

Sorry but I think that is deeper that just cobigen, the actual functionality of getBeanMapper(), is unable to handle the the LocalDate initialization.

image

That is why I create the issue to devon4j, first. Once we have this clear and tested with an example, then will be time to think how to apply into cobigen.

If you need further clarification, please ask me.

from devon4j.

hohwille avatar hohwille commented on July 29, 2024

BTW: We would love to go away from dozer and switch to Orika and have config as code. However, too little contributes and too much work... This dozer XML config is a painful source of trouble.

from devon4j.

hohwille avatar hohwille commented on July 29, 2024

For hibernate you do not need to care for JSR-310 (javax.time) anymore if you are using the version that comes with devon4j as it already includes support OOTB. That was not the case earlier.
However, from devon4j itself this is not really a bug.
We should however consider to improve the dozer config in the archetype (we can assume Java8 for every new project these days).
And please note that @maybeec just listed a few of the javax.time datatypes. There are many more (Year, Instant, MonthDay, LocalDateTime, LocalTime, etc.).

from devon4j.

jdiazgon avatar jdiazgon commented on July 29, 2024

Thanks for the feedback @jconcavi. From CobiGen side, it is an easy fix. We have to create some if conditions to check these kind of types. If one of them is found, then we will generate String.

Even I think it would be possible to modify the dozer-mapping.xml by CobiGen. But I think it is a better idea to have this on the archetype, as jconcavi said.

from devon4j.

jconcavi avatar jconcavi commented on July 29, 2024

After a chat with @maybeec , we discuss the possibility to don't modify a lot the actual behaviour.

Create the entity with the JAVA 8 Date/Time Api, and anfter use cobigen, in the Eto, use the follwing annotations to serialize and deserialize the Date / Time classes to String or implement your own:

  @JsonDeserialize(using = LocalDateDeserializer.class)
  @JsonSerialize(using = LocalDateSerializer.class)
  @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
  private LocalDate dateForSomething;

from devon4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.