Open theladyjaye opened 4 years ago
I bet it would be achievable by using different contexts if your modules are just a convenient way to structure the project imho Another way to solve your problem is to use difference transformers/mappers/serializers explicitly as you mentioned. Remember that if your data class has private props then you have to assign them manually.
Your model:
What you did:
What you expected:
So, I have extensions in different modules that require different kinds of deserialization. In the above example, the response from the API has the field
nameFromAPIRequestField
which is beyond my control; no worries, it maps easily enough. Now enter the issue. We don't want to make API request all the time for everything, so we Cache these, but we also restructure things for the local cache storage engine. In this case when we write the cache record (JSON Document Store (Couchbase in this case)) and use the field namename
instead of the API response fieldnameFromAPIRequestField
.At runtime we will get:
That makes sense as we have 2 modules loaded and BOTH have the same extension methods declared. Stepping through the code it looks like it's just confused on which
objectForMapping
to use and it uses the correctmapping(_: Map)
function.Now I THINK a way around this would be just just make module specific wrappers to remove the ambiguity for
objectForMapping
and just have it return the object and have an emptymapping(_: Map)
for that wrapper. Next be be sure to:Is there an alternative way or does this methodology seem sound?