devondragon / devondragon/SpringShopifyAppFramework
Update REST API classes to remove extraneous wrapper classes
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 55
- Forks
- 18
- Ø Merge
- 7 Std. 14 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
Much of the REST API model has "Root" classes which are just wrappers to handle the name of a JSON node.
I think we can get rid of all of those, by defining the actual model classes with a couple JSON annotations. An example is the Webhook class:
@JsonTypeName(value = "webhook")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
Update:
This is trickier than expected. The main approach works fine for single item use, but causes issues when there's an array of items being mapped to a collection.
For example, for a single Product call, Shopify returns something like:
{
"product": {
"id": 632910392,
"title": "IPod Nano - 8GB",
"body_html": "
It's the small iPod......
Which is why we need the Product class to have the As.WRAPPER_OBJECT annotation (or the wrapper class).
However, when getting an array of products, Shopify sends in something like this:
{
"products": [
{
"id": 632910392,
"title": "IPod Nano - 8GB",
"body_html": "
It's the small iPo
Note the lack of "product" level nodes. That's what breaks here. So basically we want Product to wrap itself with a "product" node if it's a single Product, but to NOT wrap itself when its an array or collection. I can't find any easy way to do this. A custom de-serializer is an option, but I'm not sure that's a lot better/cleaner than these wrapper classes....
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit den REST API-Modellklassen, einschließlich Webhook und Product, und vergleichen Sie, wie Jackson-Wrapper-Annotationen einzelne Objekte gegenüber Sammlungen behandeln. Reproduzieren Sie die dokumentierten Product- und products-Antwortformen und ermitteln Sie anschließend, ob die Root-Wrapper entfernt werden können, wobei beide Deserialisierungsformen erhalten bleiben; das Issue nennt keine bestimmten Dateien oder Tests.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java, spring-boot
- Bereich
- api, backend
- Issue-Typ
- Refactoring
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100