Last active
October 9, 2024 21:37
-
-
Save dacr/1f0cf2fab4c8b24d37a40e94e8230839 to your computer and use it in GitHub Desktop.
chimney interaction with java records / published by https://github.com/dacr/code-examples-manager #cef5665e-18c0-4c3a-b7e1-cc732719fbc6/63b2170f6a8cdcae1f4f0d916c6fddbe72e25a4d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : chimney interaction with java records | |
// keywords : scala, chimney, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache2 | |
// id : cef5665e-18c0-4c3a-b7e1-cc732719fbc6 | |
// created-on : 2024-10-09T20:02:20+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// attachments: SomeoneDAO.java | |
// run-with : scala-cli main.sc SomeoneDAO.java | |
//> using scala "3.5.1" | |
//> using dep "io.scalaland::chimney:1.5.0" | |
//> using dep com.lihaoyi::pprint::0.9.0 | |
//> using javacOpt -proc:none | |
import io.scalaland.chimney.dsl.* | |
import pprint.* | |
import java.time.OffsetDateTime | |
{ | |
implicit val config = TransformerConfiguration.default.enableMethodAccessors | |
case class SomeoneDTO(firstName: String, lastName: String, birthDate: OffsetDateTime) | |
val dao = SomeoneDAO("john", "Doe", OffsetDateTime.now) | |
val dto = dao.transformInto[SomeoneDTO] | |
pprintln(dto) | |
val backToDao = dto.transformInto[SomeoneDAO] | |
pprintln(backToDao) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.OffsetDateTime; | |
public record SomeoneDAO(String firstName, String lastName, OffsetDateTime birthDate) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment