-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1496 from ISISComputingGroup/fix_macro_defaults
Fix deserialization of attributes marked with @SerializedName
- Loading branch information
Showing
5 changed files
with
91 additions
and
8 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
49 changes: 49 additions & 0 deletions
49
...uk/ac/stfc/isis/ibex/epics/tests/conversion/json/LowercaseEnumTypeAdapterFactoryTest.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,49 @@ | ||
package uk.ac.stfc.isis.ibex.epics.tests.conversion.json; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import uk.ac.stfc.isis.ibex.epics.conversion.ConversionException; | ||
import uk.ac.stfc.isis.ibex.epics.conversion.json.LowercaseEnumTypeAdapterFactory; | ||
|
||
@RunWith(MockitoJUnitRunner.Strict.class) | ||
public class LowercaseEnumTypeAdapterFactoryTest { | ||
|
||
public static enum TestEnum { | ||
IMPLICIT_ONE, | ||
IMPLICIT_TWO; | ||
} | ||
|
||
public static enum TestEnumWithSerializedName { | ||
@SerializedName("name1") EXPLICIT_ONE, | ||
@SerializedName("name2") EXPLICIT_TWO; | ||
} | ||
|
||
public static enum TestEnumMixed { | ||
MIXED_ONE, | ||
@SerializedName("explicit_name") MIXED_TWO; | ||
} | ||
|
||
@Test | ||
public void convert_enum() throws ConversionException { | ||
Gson gson = new GsonBuilder() | ||
.registerTypeAdapterFactory(new LowercaseEnumTypeAdapterFactory()) | ||
.create(); | ||
|
||
assertEquals(TestEnum.IMPLICIT_ONE, gson.fromJson("\"implicit_one\"", TestEnum.class)); | ||
assertEquals(TestEnum.IMPLICIT_TWO, gson.fromJson("\"implicit_two\"", TestEnum.class)); | ||
|
||
assertEquals(TestEnumWithSerializedName.EXPLICIT_ONE, gson.fromJson("\"name1\"", TestEnumWithSerializedName.class)); | ||
assertEquals(TestEnumWithSerializedName.EXPLICIT_TWO, gson.fromJson("\"name2\"", TestEnumWithSerializedName.class)); | ||
|
||
assertEquals(TestEnumMixed.MIXED_ONE, gson.fromJson("\"mixed_one\"", TestEnumMixed.class)); | ||
assertEquals(TestEnumMixed.MIXED_TWO, gson.fromJson("\"explicit_name\"", TestEnumMixed.class)); | ||
} | ||
} |
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