0

I ran into a multiple inheritance problem while trying to use moshi for serialization/de-serialization and Sugar ORM for the database of my Android project. Each library expects my model (POJO) to extend their classes for them to work. I already extended moshi's class but I can't figure out how to deal with Sugar ORM since multiple inheritance is not allowed in Java. There also seems to be a getId() method clash in the classes I'm supposed to extend for both libraries. What is the best way to go about solving this problem? I specifically chose moshi and not Gson (which I usually used before) because of its support for the JSON API specification used by the API I'm consuming

Ken
  • 179
  • 10
  • I'd suggest changing one of your libraries. It doesn't sound like they're compatible. Although I'm not getting why you think you need to derive from some specific class for moshi- I don't see that in the api docs at all. – Gabe Sechan Jul 17 '17 at 20:48
  • @GabeSechan I don't know about the normal moshi but the the part used for [json api](https://github.com/kamikat/moshi-jsonapi) specifically says you have to extend Resource in each model. I tried without extending it but the builder won't accept my class – Ken Jul 17 '17 at 20:57
  • Ah. That isn't Moshi, that's some other library built on top of moshi. But yeah, I don't see any easy way of making it work with Sugar ORM. – Gabe Sechan Jul 17 '17 at 21:02
  • @Ken, If you are open to trying another ORM that does not require you to extend your model classes from any base class and that can also persist JSON objects, you may want to check out JDXA ORM for Android. Disclaimer: I am the architect of JDXA ORM. – Damodar Periwal Jul 18 '17 at 02:36
  • @DamodarPeriwal that's great, looks powerful and does not impose anything on the model classes, but then introduces a new DSL. I guess many people use ORMs because they don't want to deal with raw sql or other domain-specific-languages and just write their code in the programming languages. Great ORM though! – Ken Jul 18 '17 at 08:16
  • @Ken, Thanks for your comments. The mapping has to be defined somewhere. JDXA ORM specification is based on a simple and intuitive grammar; it is compact and easy to learn - most of the default specification is deduced automatically. The ORM specification is non-intrusive - it does not clutter the source code. Here are some code snippets: http://softwaretree.com/v1/products/jdxa/code-snippets.html – Damodar Periwal Jul 18 '17 at 20:01
  • @DamodarPeriwal so how do you ignore some fields? – Ken Jul 19 '17 at 00:12
  • @Ken, you can ignore one or more fields using an IGNORE mapping specification. For example, specify "IGNORE a1 a2" to ignore two fields a1 and a2. See http://softwaretree.com/v1/products/jdxa/simple_mapping2.html – Damodar Periwal Jul 19 '17 at 01:25
  • Java supports multiple inheritance through interfaces only. A class can implement any number of interfaces but can extend only one class. – Jon Goodwin Aug 18 '17 at 12:25

0 Answers0