-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/disposition not deserializing default field (#342)
* fix(ffprobe): Correctly deserialize dispositions * chore: Add missing @OverRide annotation * chore: Check if element is primitive before converting * test: Add explicit tests for string based boolean
- Loading branch information
Showing
6 changed files
with
123 additions
and
249 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
26 changes: 26 additions & 0 deletions
26
src/main/java/net/bramp/ffmpeg/adapter/BooleanTypeAdapter.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,26 @@ | ||
package net.bramp.ffmpeg.adapter; | ||
|
||
import java.lang.reflect.Type; | ||
import com.google.gson.*; | ||
|
||
public class BooleanTypeAdapter implements JsonDeserializer<Boolean> { | ||
@Override | ||
public Boolean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isBoolean()) { | ||
return json.getAsBoolean(); | ||
} | ||
|
||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) { | ||
String jsonValue = json.getAsString(); | ||
if (jsonValue.equalsIgnoreCase("true")) { | ||
return true; | ||
} else if (jsonValue.equalsIgnoreCase("false")) { | ||
return false; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
return json.getAsInt() != 0; | ||
} | ||
} |
142 changes: 0 additions & 142 deletions
142
src/main/java/net/bramp/ffmpeg/gson/NamedBitsetAdapter.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/main/java/net/bramp/ffmpeg/probe/FFmpegDisposition.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
66 changes: 66 additions & 0 deletions
66
src/test/java/net/bramp/ffmpeg/adapter/BooleanTypeAdapterTest.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,66 @@ | ||
package net.bramp.ffmpeg.adapter; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.annotations.JsonAdapter; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
public class BooleanTypeAdapterTest { | ||
static class Set { | ||
@JsonAdapter(BooleanTypeAdapter.class) | ||
public boolean a; | ||
} | ||
|
||
static Gson gson; | ||
|
||
@BeforeClass | ||
public static void setupGson() { | ||
gson = new GsonBuilder().create(); | ||
} | ||
|
||
@Test | ||
public void testReadTrue() { | ||
Set s = gson.fromJson("{\"a\":true}", Set.class); | ||
assertTrue(s.a); | ||
} | ||
|
||
@Test | ||
public void testReadFalse() { | ||
Set s = gson.fromJson("{\"a\":false}", Set.class); | ||
assertFalse(s.a); | ||
} | ||
|
||
@Test | ||
public void testReadStringTrue() { | ||
Set s = gson.fromJson("{\"a\":\"true\"}", Set.class); | ||
assertTrue(s.a); | ||
} | ||
|
||
@Test | ||
public void testReadStringFalse() { | ||
Set s = gson.fromJson("{\"a\":\"false\"}", Set.class); | ||
assertFalse(s.a); | ||
} | ||
|
||
@Test | ||
public void testRead1() { | ||
Set s = gson.fromJson("{\"a\":1}", Set.class); | ||
assertTrue(s.a); | ||
} | ||
|
||
@Test | ||
public void testRead0() { | ||
Set s = gson.fromJson("{\"a\":0}", Set.class); | ||
assertFalse(s.a); | ||
} | ||
|
||
@Test | ||
public void testReadNull() { | ||
Set s = gson.fromJson("{\"a\":null}", Set.class); | ||
assertFalse(s.a); | ||
} | ||
} |
Oops, something went wrong.