Comments (3)
you can do this:
A a = ....;
String json = JSON.toJSONString(a);
B b = JSON.parseObject(json, B.class);
from fastjson.
Of course, this way is possible for conversion of objects, but:
- This method is slowly
- I can't control the binding, such as mapping a field 'fieldA' of class 'A' to field 'fieldB' of class 'B'
I'd like to have possibility like this code (for shortly in groovy-style)
class A {String fieldA}
class B {C fieldB}
class C {String fieldC}
ParserConfig.getGlobalInstance().addMapping(
new ClassMap(from: A.class, to: B.class, fields: [['fieldA', 'fieldB.fieldC'']])
FastBinding.convert(new A(fieldA: '123'), new B())
It implements not very hard if there is a factory of data binding
from fastjson.
P.S.: I want to develop a universal dao find method, which receives result data from DB with JPA Entity and
converts theirs to a web data service response type.
This facility is possible when using DozerMapper, by mapping web data type to JPA Entity.
But, if I like to receive result as Tuple - transformation impossible.
DozerMapper is a very closed system.
I hope to use fastjson for this purpose, because it's very flexible system.
from fastjson.
Related Issues (20)
- Android中序列化Context、Activity、Fragment导致StackOverflowError
- com.alibaba.fastjson.JSONException: GC overhead limit exceeded
- With IgnoreErrorGetter & WriteClassName to serialize , the value of number (short、double) with precision letter
- FastJson 1.2.83存在未在黑名单内的JDK原生可利用类
- 日期少0反序列化报错 HOT 1
- 使用线程池序列化时,有概率会出现ref循环引用问题 HOT 1
- 对UTC时间,非三位小数点的毫秒解析错误
- 重复了 关
- 有关fastjson设计上的问题
- 高版本反序列化时不能识别字段名
- 使用 graalvm 构建可执行文件,执行后发生: No classes have been predefined during the image build to load from bytecodes at runtime.
- jdk 11 fastjson 1.2.83 报 java.net.http does not export jdk.internal.net.http to unnamed module @0x67ecfe55
- ObjectSerializer元数据空间溢出。只有一个SerializeConfig实例 HOT 2
- fastjson 版本支持问题
- FastJsonHttpMessageConverter自定义 Long类型的Deserializer不生效 HOT 1
- 1.2.83版本 long类型反序列化位数超出后会无感处理溢出
- 1.2.83 版本使用 JSON.parseObject 方法转换字符串时,会报OOM HOT 8
- 1.2.74 java.lang.ClassCastException: byte[] cannot be cast to int[]
- android14解析高德定位信息失败
- Version 1.2.83 failed to deserialize certain value when its ref path contains dash
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastjson.