-
Notifications
You must be signed in to change notification settings - Fork 4
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
Marek Sontag
committed
Sep 21, 2020
1 parent
d952886
commit eb96b2e
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
.../src/test/java/com/infobip/jackson/PresentPropertyResolverWithDefaultConstructorTest.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,59 @@ | ||
package com.infobip.jackson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.google.common.base.CaseFormat; | ||
import lombok.*; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
public class PresentPropertyResolverWithDefaultConstructorTest extends TestBase { | ||
|
||
@Test | ||
void shouldUseResolverWithNoArgsConstructor() throws JsonProcessingException { | ||
// given | ||
String json = objectMapper.writeValueAsString(new RoadBike("road bike")); | ||
|
||
// when | ||
Bike actual = objectMapper.readValue(json, Bike.class); | ||
|
||
// then | ||
then(actual).isEqualTo(new RoadBike("road bike")); | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
enum BikeType implements TypeProvider { | ||
ROAD_BIKE(RoadBike.class), | ||
MOUNTAIN_BIKE(MountainBike.class); | ||
|
||
private final Class<? extends Bike> type; | ||
} | ||
|
||
@JsonTypeResolveWith(BikeTypeResolver.class) | ||
interface Bike extends PresentPropertyJsonHierarchy<BikeType> { | ||
|
||
} | ||
|
||
static class BikeTypeResolver extends PresentPropertyJsonTypeResolver<BikeType> { | ||
|
||
public BikeTypeResolver() { | ||
super(BikeType.class, CaseFormat.LOWER_CAMEL); | ||
} | ||
} | ||
|
||
@AllArgsConstructor(onConstructor_ = @JsonCreator) | ||
@Value | ||
static class RoadBike implements Bike { | ||
|
||
private final String roadBike; | ||
} | ||
|
||
@AllArgsConstructor(onConstructor_ = @JsonCreator) | ||
@Value | ||
static class MountainBike implements Bike { | ||
|
||
private final String mountainBike; | ||
} | ||
} |