Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.time.Instant Not Supported #731

Closed
stevenpaligo opened this issue Nov 28, 2018 · 3 comments
Closed

java.time.Instant Not Supported #731

stevenpaligo opened this issue Nov 28, 2018 · 3 comments

Comments

@stevenpaligo
Copy link

Despite the date/time changes in 6.4.0, conversions of java.time.Instant are still not supported. Would you please add that?

Whats your runtime?

  • Dozer version: 6.4.1
  • OS version: Windows 10
  • JDK version: 8

Whats the problem?

POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.stevenpaligo</groupId>
  <artifactId>dozer-test</artifactId>
  <version>1.0.0</version>

  <name>Dozer Test</name>

  <properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

  </properties>

  <dependencies>

    <dependency>
      <groupId>com.github.dozermapper</groupId>
      <artifactId>dozer-core</artifactId>
      <version>6.4.1</version>
    </dependency>

  </dependencies>

</project>

dozerBeanMapping.xml:

<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping https://dozermapper.github.io/schema/bean-mapping.xsd">

	<mapping wildcard="true" type="one-way">
		<class-a>test.Test.Left</class-a>
		<class-b>test.Test.Right</class-b>
	</mapping>

</mappings>

Test classes:

package test;

import java.time.Instant;
import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;

public class Test {

  public static void main(String[] args) {

    Mapper mapper = DozerBeanMapperBuilder.buildDefault();

    Instant now = Instant.now();

    Left left = new Left();
    left.setTime(now);

    Right right = mapper.map(left, Right.class);

    System.out.println(now);
    System.out.println(right.getTime());
  }


  public static class Left {

    private Instant time;


    public Instant getTime() {
      return time;
    }


    public void setTime(Instant time) {
      this.time = time;
    }
  }


  public static class Right {

    private Instant time;


    public Instant getTime() {
      return time;
    }


    public void setTime(Instant time) {
      this.time = time;
    }
  }
}

Observed Results:

The following exception is thrown because Instant doesn't have a constructor:

Exception in thread "main" com.github.dozermapper.core.MappingException: java.lang.NoSuchMethodException: java.time.Instant.()

Expected Results:

The given code should write the converted time to system out.

@garethahealy
Copy link
Collaborator

Just had a quick check of the PR that provided java8 datetime. cant see Instant -> Instant

@stevenpaligo ; If you want to add support, that would be helpful as i dont have much spare time currently. Just have a look at the above PR and raise a PR adding Instant support

@garethahealy
Copy link
Collaborator

#742

@AdrienViala
Copy link

Hello @garethahealy ,

Do you plan on releasing soon in order to provide the Java.time.Instant support ?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants