[英]Sharing classes between Android application and Jersey server application
I'm building an Android application that will talk to a web service built in Java and Jersey. 我正在构建一个Android应用程序,该程序将与Java和Jersey内置的Web服务对话。
I've currently organized three projects: 我目前组织了三个项目:
The core library is a project dependency for each of the other two. 核心库是其他两个项目的项目依赖项。
The problem is that I've created my set of entity classes in "core", but those classes are configured for Morphia using annotations. 问题是我已经在“核心”中创建了一组实体类,但是这些类是使用注释为Morphia配置的。 This means Morphia in turn becomes a dependency on my Android application, which I don't particularly like. 这意味着Morphia反过来又成为我特别不喜欢的Android应用程序的依赖项。
Ideally, Morphia would allow configuration via flat files but it only supports configuring entity classes via annotations. 理想情况下,Morphia允许通过平面文件进行配置,但仅支持通过注释配置实体类。
Should I suck up the ugly dependency of 'core' relying on Morphia, or is there a better way to organize my classes that I'm not thinking of? 我应该吸收依赖Morphia的“核心”的丑陋依赖,还是有一种更好的方式来组织我没有想到的课程?
Note: I have tried removing the Morphia annotations from the core classes, and created new classes in the "server" project that inherit the "core" classes and add the Morphia annotations. 注意:我已经尝试从核心类中删除Morphia批注,并在“服务器”项目中创建了继承“核心”类并添加Morphia批注的新类。 However, if my Jersey application returns classes from the server project, then the Android client can't use those classes with the Jersey client. 但是,如果我的Jersey应用程序从服务器项目返回了类,则Android客户端无法将这些类与Jersey客户端一起使用。
Thanks 谢谢
I did end up switching to a different POJO mapper. 最后我确实切换到了另一个POJO映射器。 I've decided to go with Kundera. 我决定和昆德拉一起去。 This effectively creates only one dependency on javax-persistence
in my core project (for JPA annotations). 这实际上在我的核心项目中(对于JPA批注)仅对javax-persistence
创建了一个依赖项。
You could switch from Morphia to another MongoDB pojo mapper that uses Jackson annotations such as mongo-jackson-mapper or bson4jackson . 您可以从Morphia切换到另一个使用Jackson注释(例如mongo-jackson-mapper或bson4jackson)的 MongoDB pojo映射器 。 This way your Android project would have dependencies on Jackson instead of Morphia. 这样,您的Android项目将依赖于Jackson而不是Morphia。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.