victoralbertos / jolyglot Goto Github PK
View Code? Open in Web Editor NEWAgnostic Json abstraction to perform data binding operations for Android and Java.
License: Apache License 2.0
Agnostic Json abstraction to perform data binding operations for Android and Java.
License: Apache License 2.0
GsonSpeaker implements JolyglotGenerics,but,FastJsonSpeaker implements Jolyglot.
RxCache.Builder() .persistence() not do FastJsonSpeaker ?
Currently, both generic
and non generic
objects binding operations are defined in the same interface
.
Split them in order to provide a more granular selecction and support another json providers which only could work with non generic
objects.
Plus, in case generics
are not required and the user of the Jolyglot does not want to use any of the built-in json providers, the complexity of a manual implementation of Jolyglot would be far less.
I use this class in Kotlin because Newparameterizedtype method error, not in Rxcache normal use, please use Java code to see if the normal use
implementation "com.alibaba:fastjson:1.1.64.android"
public class FastJsonSpeaker implements JolyglotGenerics {
@Override
public String toJson(Object src, Type typeOfSrc) {
return JSON.toJSONString(src);
}
@Override
public <T> T fromJson(String json, Type type) throws RuntimeException {
return JSON.parseObject(json, type);
}
@Override
public <T> T fromJson(File file, Type typeOfT) throws RuntimeException {
String json = readFile2String(file);
return JSON.parseObject(json, typeOfT);
}
@Override
public GenericArrayType arrayOf(Type componentType) {
return Types.arrayOf(componentType);
}
@Override
public ParameterizedType newParameterizedType(Type rawType, Type... typeArguments) {
return Types.newParameterizedType(rawType, typeArguments);
}
@Override
public String toJson(Object src) {
return JSON.toJSONString(src);
}
@Override
public <T> T fromJson(String json, Class<T> classOfT) throws RuntimeException {
return JSON.parseObject(json, classOfT);
}
@Override
public <T> T fromJson(File file, Class<T> classOfT) throws RuntimeException {
String json = readFile2String(file);
return JSON.parseObject(json, classOfT);
}
private static String readFile2String(File file) {
if (file == null || !file.exists()) {
return null;
}
BufferedReader reader = null;
try {
StringBuilder sb = new StringBuilder();
if (StringUtils.isSpace("UTF-8")) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
} else {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
}
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
With update from 0.0.3 to 0.0.5 and even 0.0.6 version there are missing transitive dependencies that we are expecting to be there like the Types class from common module and in my case the jackson library (com.fasterxml.jackson package) is missing. Is this expected behavior?
I'm trying to upgrade from 0.0.3 to 0.0.5 but Gradle is unable to resolve the library, as if this version is not available on Jitpack. I get the following error when trying to synce Gradle Failed to resolve: com.github.VictorAlbertos.Jolyglot:jackson:0.0.5
The MoshiSpeaker
implementation of JolyglotGenerics
does not close the BufferedSource
object, this is not a breaking problem on some Linux based distributions but can lead to breaking problems on Windows based machines.
But anyway, this is bad behavior and should be fixed, isn't it 😉?
The GsonSpeaker
doesn't seem to have this problem.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.