forked from bramp/ffmpeg-cli-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFmpegStreamSideDataAdapter.java
More file actions
28 lines (25 loc) · 1.25 KB
/
FFmpegStreamSideDataAdapter.java
File metadata and controls
28 lines (25 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package net.bramp.ffmpeg.adapter;
import com.google.gson.*;
import net.bramp.ffmpeg.probe.FFmpegStream;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
public class FFmpegStreamSideDataAdapter implements JsonDeserializer<FFmpegStream.SideData> {
@Override
public FFmpegStream.SideData deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
if (!(jsonElement instanceof JsonObject)) return null;
try {
Object sideData = Class.forName(FFmpegStream.SideData.class.getName()).getConstructor().newInstance();
Field[] fields = Class.forName(FFmpegStream.SideData.class.getName()).getFields();
for (Field field: fields) {
String fieldName = field.getName();
AnnotatedType annotatedType = field.getAnnotatedType();
Object deserialize = jsonDeserializationContext.deserialize(((JsonObject) jsonElement).get(fieldName), annotatedType.getType());
field.set(sideData, deserialize);
}
return (FFmpegStream.SideData) sideData;
} catch (Exception exception) {
return null;
}
}
}