-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
392 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
33 changes: 33 additions & 0 deletions
33
domino-jackson-processor/src/it/java/org/dominokit/jackson/records/Circle.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dominokit.jackson.records; | ||
|
||
import org.dominokit.jackson.annotation.JSONMapper; | ||
|
||
@JSONMapper | ||
public record Circle(double radius) { | ||
public static final double PI = 3.14159; | ||
|
||
public Circle { | ||
if (radius < 0) { | ||
throw new IllegalArgumentException("Radius cannot be negative"); | ||
} | ||
} | ||
|
||
public double area() { | ||
return PI * radius * radius; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
domino-jackson-processor/src/it/java/org/dominokit/jackson/records/ComplexNumber.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dominokit.jackson.records; | ||
|
||
import org.dominokit.jackson.annotation.JSONMapper; | ||
|
||
@JSONMapper | ||
public record ComplexNumber(double real, double imaginary) { | ||
public ComplexNumber(double real) { | ||
this(real, 0); // Calls the canonical constructor with 0 for the imaginary part | ||
} | ||
|
||
public double magnitude() { | ||
return Math.sqrt(real * real + imaginary * imaginary); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
domino-jackson-processor/src/it/java/org/dominokit/jackson/records/Point.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dominokit.jackson.records; | ||
|
||
import org.dominokit.jackson.annotation.JSONMapper; | ||
|
||
@JSONMapper | ||
public record Point(int x, int y) { | ||
} |
63 changes: 63 additions & 0 deletions
63
domino-jackson-processor/src/it/java/org/dominokit/jackson/records/RecordIT.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dominokit.jackson.records; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class RecordIT { | ||
|
||
private static final Point_MapperImpl POINT_MAPPER = new Point_MapperImpl(); | ||
private static final Circle_MapperImpl CIRCLE_MAPPER = new Circle_MapperImpl(); | ||
private static final ComplexNumber_MapperImpl COMPLEX_NUMBER_MAPPER = new ComplexNumber_MapperImpl(); | ||
private static final Rectangle_MapperImpl RECTANGLE_MAPPER = new Rectangle_MapperImpl(); | ||
|
||
@Test | ||
public void simpleRecordTest(){ | ||
String pointJson = POINT_MAPPER.write(new Point(10, 20)); | ||
Point point = POINT_MAPPER.read(pointJson); | ||
|
||
Assert.assertEquals("{\"x\":10,\"y\":20}", pointJson); | ||
Assert.assertEquals(10, point.x()); | ||
Assert.assertEquals(20, point.y()); | ||
Assert.assertEquals(new Point(10, 20), point); | ||
|
||
String circleJson = CIRCLE_MAPPER.write(new Circle(10.0)); | ||
Circle circle = CIRCLE_MAPPER.read(circleJson); | ||
|
||
Assert.assertEquals("{\"radius\":10.0}", circleJson); | ||
Assert.assertEquals(10.0, circle.radius(), 0.001); | ||
Assert.assertEquals(new Circle(10), circle); | ||
|
||
String complexNumberJson = COMPLEX_NUMBER_MAPPER.write(new ComplexNumber(10.0)); | ||
ComplexNumber complexNumber = COMPLEX_NUMBER_MAPPER.read(complexNumberJson); | ||
|
||
Assert.assertEquals("{\"real\":10.0,\"imaginary\":0.0}", complexNumberJson); | ||
Assert.assertEquals(10.0, complexNumber.real(), 0.001); | ||
Assert.assertEquals(0, complexNumber.imaginary(), 0.001); | ||
Assert.assertEquals(new ComplexNumber(10.0), complexNumber); | ||
|
||
String rectangleJson = RECTANGLE_MAPPER.write(new Rectangle(new Point(10,20), new Point(20, 30))); | ||
Rectangle rectangle = RECTANGLE_MAPPER.read(rectangleJson); | ||
|
||
Assert.assertEquals("{\"bottomLeft\":{\"x\":10,\"y\":20},\"topRight\":{\"x\":20,\"y\":30}}", rectangleJson); | ||
Assert.assertEquals(new Point(10, 20), rectangle.a()); | ||
Assert.assertEquals(new Point(20, 30), rectangle.b()); | ||
Assert.assertEquals(new Rectangle(new Point(10,20), new Point(20, 30)), rectangle); | ||
|
||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
domino-jackson-processor/src/it/java/org/dominokit/jackson/records/Rectangle.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dominokit.jackson.records; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.dominokit.jackson.annotation.JSONMapper; | ||
|
||
@JSONMapper | ||
public record Rectangle(@JsonProperty("bottomLeft") Point a, @JsonProperty("topRight") Point b) { | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.