为了解决我在这个线程中讨论的类型不匹配问题,我创建了自定义Deserializers并将它们添加到ObjectMapper.然而,性能随之显着恶化.
使用默认的解串器,我可以获得1-2个垃圾收集调用,logcat而使用自定义解串器时,至少有7-8个GC调用,因此处理时间也会显着增加.
我的解串器:
public class Deserializer<T> {
public JsonDeserializer<T> getDeserializer(final Class<T> cls) {
return new JsonDeserializer<T> (){
@Override
public T deserialize(JsonParser jp, DeserializationContext arg1) throws IOException, JsonProcessingException {
JsonNode node = jp.readValueAsTree();
if (node.isObject()) {
return new ObjectMapper().convertValue(node, cls);
}
return null;
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用它添加到Mapper
public class DeserializerAttachedMapper<T> {
public ObjectMapper getMapperAttachedWith(final Class<T> cls , JsonDeserializer<T> deserializer) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule(deserializer.toString(), …Run Code Online (Sandbox Code Playgroud) 我有一个简单的测试用例,用于测试是否在按钮点击时启动了拨出呼叫.
public void testCalling(){
IntentFilter callFilter = new IntentFilter();
callFilter.addAction(Intent.ACTION_CALL);
callFilter.addCategory(Intent.CATEGORY_DEFAULT);
callFilter.addDataScheme("tel:");
ActivityMonitor mMonitor = new ActivityMonitor(callFilter, null, false);
getInstrumentation().addMonitor(mMonitor);
mSolo.clickOnText("CALL");
assertTrue(0 < mMonitor.getHits());
sendKeys(KeyEvent.KEYCODE_ENDCALL);
}
Run Code Online (Sandbox Code Playgroud)
虽然调用了Intent(传出调用),但我的ActivityMonitor无法注册它.堆栈跟踪是
05-28 17:11:09.183: I/ActivityManager(71): Starting activity: Intent { act=android.intent.action.CALL dat=tel:+xxxxxxx cmp=com.android.phone/.OutgoingCallBroadcaster }
Run Code Online (Sandbox Code Playgroud)
请帮忙
我能找到的唯一其他资源就是这个讨论在Android开发者小组没有任何解决方案的情况下结束
我收到以下从服务器生成的响应 cakephp
[
{
"id": "42389",
"start": "0000-00-00",
"end": "0000-00-00",
"event_id": null,
"trip_id": "5791",
"location_id": "231552",
"user_id": "105",
"users_attending": "0",
"user_local": "0",
"Trip": {
"name": "Asdas"
},
"Event": [],
"Location": {
"name": "South Melbourne"
}
},
{
"id": "42392",
"start": "0000-00-00",
"end": "0000-00-00",
"event_id": "1218",
"trip_id": "4772",
"location_id": "271505",
"user_id": "105",
"users_attending": "3",
"user_local": "50",
"Trip": {
"name": "trip by 1059200"
},
"Event": {
"title": "SampleEvent 454",
"id": "1218"
},
"Location": {
"name": "Houston"
}
},
.......
]
Run Code Online (Sandbox Code Playgroud)
问题是解析器需要Event …