简体   繁体   English

在Android应用程序与Jersey服务器应用程序之间共享类

[英]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: 我目前组织了三个项目:

  • core (common) is a simple set of POJOs for my domain models 核心(通用)是针对我的域模型的一组简单的POJO
  • client (android) is the Android application 客户端(android)是Android应用程序
  • server (jersey) is a Jersey application storing data in MongoDB and relying on the Morphia library for persistence. 服务器(球衣)是一个Jersey应用程序,用于在MongoDB中存储数据,并依赖Morphia库进行持久化。

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-mapperbson4jackson)的 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.

相关问题 在Android应用程序中的用户之间共享数据 - Sharing data between users in Android application 在 Java 后端和 Android 应用程序之间共享 POJO - Sharing POJOs between Java backend and an Android application 在android和PC应用程序之间共享库 - Sharing a library between android and a PC application 我应该如何构建我的项目以在Android客户端应用程序和JSP服务器应用程序之间共享类? - How should I structure my project to share classes between an Android client application and a JSP server application? 在WEB API服务器和Android客户端应用程序之间共享模型的最佳实践是什么 - What is the best practice for sharing models between a WEB API server and an Android client application Android:在本机代码(C)和应用程序(java)之间共享数据 - Android: Sharing data between native code (C) and application (java) 在JavaSE和Web应用程序之间共享应用程序上下文 - Sharing application context between JavaSE and Web Application 在android客户端和GAE端点之间共享类 - Sharing classes between android client and GAE Endpoints 在Android Studio中的OnClick类之间共享数组 - Sharing an Array between OnClick classes in Android Studio 将文件保存到Jersey API中的服务器应用程序目录中 - Save file to server application directory in Jersey API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM