将 JAXB 与 Google Android 一起使用 [英] Using JAXB with Google Android

查看:24
本文介绍了将 JAXB 与 Google Android 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析通过 xml 传递的 java 对象.我想将 JAXB 框架用于这些目的,因为我已经预先注释(使用 JAXB)java 类.

I need to parse the java-objects which are passed through xml. I want to use for these purposes JAXB framework, because I have pre-annotated (using JAXB) java-class.

这原则上可行吗?

InputStream input = entity.getContent();
JAXBContext jc = JAXBContext.newInstance(new Class[] {Response.LoginResponse.class});
Unmarshaller un = jc.createUnmarshaller();
LoginResponse response = (LoginResponse)un.unmarshal(input);

在第 4 行,我有一个警告:无法解析静态方法 282 JAXBContext ..."然后虚拟机崩溃

in line 4, I have a warning: "unable to resolve static method 282 JAXBContext ... " and then VM crashes

关于如何解决这个问题的任何想法?

Any ideas on how to solve this problem?

推荐答案

我并没有完全解决您的问题,但 JAXB 默认不包含在 android 中,该库将花费您 9(!) MB 的 apk.改用 SimpleXML.它具有类似的能力,而且更轻量级.

I'm not exactly resolving your problem, but JAXB isn't included in android by default and the library will cost you 9(!) MB of your apk. Try SimpleXML instead. It has similiar abilities and much more lightweight.

这篇关于将 JAXB 与 Google Android 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆