Skip to content

Allow empty paths to merge nested data into the top level.#23

Open
seyfahni wants to merge 1 commit intosquare:mainfrom
seyfahni:fix-serialize-empty-path
Open

Allow empty paths to merge nested data into the top level.#23
seyfahni wants to merge 1 commit intosquare:mainfrom
seyfahni:fix-serialize-empty-path

Conversation

@seyfahni
Copy link
Contributor

@seyfahni seyfahni commented Mar 8, 2023

Deserialization of properties marked with #[Json(path: []) did already work, but serialization did not.

I wrote tests to verify this behavior and adjusted the Json class to make serialization work too.

My tests cover the following cases (both serialization and deserialization):

  • object contains a property that has an empty path and is merged into the containing objects json data
  • multiple levels of zero-path merging
  • multiple objects that have the same path prefix are merged together

You can of course decide if you want this to be officially possible.

@CLAassistant
Copy link

CLAassistant commented Mar 8, 2023

CLA assistant check
All committers have signed the CLA.

@seyfahni seyfahni force-pushed the fix-serialize-empty-path branch from f811a14 to d9fe6b9 Compare March 8, 2023 08:58
@khepin
Copy link
Contributor

khepin commented Mar 8, 2023

I'll have to sit on this one for a while. I'm not fully convinced this is something we'd want here

@seyfahni
Copy link
Contributor Author

seyfahni commented Mar 8, 2023

Yeah, I expected that. But it allows for some quite nice code sharing.

I created this for serializing a request that looks like one big json object, but has a few fields that are decided based on another values content. And with this you can just inline those values instead or duplicating much of the code (all the other values).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants