Closed MisterMunchkin closed 1 year ago
Unless I'm missing or misunderstanding something, this is already supported? If you search for the string humanId
in the README.MD you'll find an example which does exactly what you are proposing.
Yea I'm not sure what the problem is now because I tried creating a stackblitz for it and can't replicate the issue I'm having on my repo.
It might be that I'm using the beta NextJs appDir but yea not sure right now.
I tried making the stackblitz mirror what I currently have better and was able to replicate it: https://stackblitz.com/edit/nextjs-vaprea?file=classes/test.ts
It looks like it stops working once I add a beforeSerialize that will turn the array into an object with a custom key while also removing an element.
I haven't really locked down what stops it from working exactly, but after I added the beforeSerialize that's when I was able to replicate my issue.
Hi, thank you for using my lib!
I'll check your stackblitz. I don't know how nextjs works but there were some troubles with react projects because of reacts does not support correcly decorators...
Except your test file, the project is in javascript so I tried with pure typescript stackblitz. Could you tell me if it's the behavior you want? https://stackblitz.com/edit/typescript-xqziwr?file=index.ts
In your stackblitz console it displays this
{inner_page: {…}}
inner_page: Object
new name: Object
id: "1234"
Which isn't the behavior I want because I expected id
to be page_id
which is what we set the name to in the InnerPage class
@JsonObject()
export class InnerPage {
@JsonProperty({ name: 'page_id' })
id?: string;
name: string;
}
Your case is a little bit weird 😅.
When you transform the array into a dictionary, it cannot understand that it must serialize so it returns the new object.
Ah, yea I'm not a fan of transforming it but yea, Notion API is kind of annoying to work with at the moment 😂.
It's fine, there are some workarounds I can do so this case isn't really that big of an issue.
one was to just have the property names be the same as what is needed on the API or to set up the data in a way that does not need it to transform from array to dictionary.
At least now I know what's actually causing the issue. Thanks!
Yes, the before...
and after...
functions are used to manipulate the inner data, not to modify the data structure.
In the example you published in Stackblitz, you can just rename the id
by page_id
manually, but I assume that your code is way more complex than your example ahah.
Just think that as you modify the structure before serialization, the sub-properties will not be passed to the serializer and will be returned without any kind of manipulation...
So I can close the issue?
yea that makes sense. You can close this now thanks!
Description
Hi,
First of all, thanks for this project it's been really useful.
Is there a way where we can have the name value in @JsonProperty replace the property names during serialization?
Example
Proposed Output:
Current Output:
Proposed solution
No response