BAEL-2721 Moved JsonAliasUnitTest into new module called jackson-2. (#6555)
* BAEL-2721 Examples of @JsonAlias and Gson's alternate parameter * BAEL-2721 Update class and method names for JsonAlias and GsonAlternate * BAEL-2721 move JsonAliasUnitTest into new jackson-2 module * BAEL-2721 Removed unused dependencies from pom.xml * BAEL-2721 Tidy up logback.xml * BAEL-2721 fix url in README.md
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
package com.baeldung.jackson.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Weather {
|
||||
|
||||
@JsonProperty("location")
|
||||
@JsonAlias("place")
|
||||
private String location;
|
||||
|
||||
@JsonProperty("temp")
|
||||
@JsonAlias("temperature")
|
||||
private int temp;
|
||||
|
||||
@JsonProperty("outlook")
|
||||
@JsonAlias("weather")
|
||||
private String outlook;
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getTemp() {
|
||||
return temp;
|
||||
}
|
||||
|
||||
public void setTemp(int temp) {
|
||||
this.temp = temp;
|
||||
}
|
||||
|
||||
public String getOutlook() {
|
||||
return outlook;
|
||||
}
|
||||
|
||||
public void setOutlook(String outlook) {
|
||||
this.outlook = outlook;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.baeldung.jackson.deserialization.jsonalias;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jackson.entities.Weather;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JsonAliasUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenTwoJsonFormats_whenDeserialized_thenWeatherObjectsCreated() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
Weather weather = mapper.readValue("{" +
|
||||
"\"location\": \"London\"," +
|
||||
"\"temp\": 15," +
|
||||
"\"weather\": \"Cloudy\"" +
|
||||
"}", Weather.class);
|
||||
|
||||
assertEquals("London", weather.getLocation());
|
||||
assertEquals("Cloudy", weather.getOutlook());
|
||||
assertEquals(15, weather.getTemp());
|
||||
|
||||
weather = mapper.readValue("{" +
|
||||
"\"place\": \"Lisbon\"," +
|
||||
"\"temperature\": 35," +
|
||||
"\"outlook\": \"Sunny\"" +
|
||||
"}", Weather.class);
|
||||
|
||||
assertEquals("Lisbon", weather.getLocation());
|
||||
assertEquals("Sunny", weather.getOutlook());
|
||||
assertEquals(35, weather.getTemp());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user