devondragon / devondragon/SpringShopifyAppFramework
Update REST API classes to remove extraneous wrapper classes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 55
- Forks
- 18
- Avg merge
- 7h 14m
- Merged PRs (30d)
- 4
Description
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....
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the REST API model classes, including Webhook and Product, and compare how Jackson wrapper annotations handle single objects versus collections. Reproduce the documented Product and products response shapes, then determine whether the Root wrappers can be removed while preserving both deserialization forms; the issue does not identify specific files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100