-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: new ignoreRequiredCheck flag, and serialize objects using specified class mappings #126
Feature: new ignoreRequiredCheck flag, and serialize objects using specified class mappings #126
Conversation
…d" property check being skipped, so all mapped properties become optional. Added unit and integration tests of new flag.
…present will be used to provide mappings. (If not present, uses mappings on the provided data object.)
Any prediction of when this PR will be promoted to master? |
Please allow me to look through it closely, but it should be within the next days. |
@andreas-aeschlimann Hi Andreas, apologies to bug you at a time like this. Is this any update on when this is going to the main release. Our project completely relies on this library. And not being able to serialize objects that weren't created using new operator is breaking everything. Thank you for your kind assistance. |
Agree with @sagunpandey here, I almost pulled my hair out as I couldn't figure out what I was doing wrong. Glad I was able to find this issue documented + associated PR. My use-case involves mapping camelCase properties to all lowercase characters. I create objects with nested objects as fields with the use of TypeScript's I've been able to solve my problem with a custom solution, it just isn't maintenance-friendly in the long term and feels hacky. We would love to use |
@jpabeem Can you please share your hacky way of resolution? Unless the library gets fixed, I would want to have some sort of temporary solution. |
Thank you for your messages. I will do it this weekend, latest this Monday. Apologies for the delay but I really want to look through it in a quiet minute before publishing it. |
I am also not sure if it fits your use-case, but I've implemented a flattening solution similar to this. The gist of it comes down to flattening the object to a depth of 1 and replacing the object property names to contain all lower case. It's not the prettiest and may break things in the future, that's why we would like to use @andreas-aeschlimann thanks for the quick update, much appreciated. Happy Easter! |
I was just wondering @cmolodo, why have you chosen Anyway, this pull request has been merged and I published v1.3.0. I also updated the docs because it was forgotten in the changes. |
@andreas-aeschlimann @cmolodo You guys rock. I will make a few tests and see everything is intact. Thanks again. |
@andreas-aeschlimann After upgrading to v1.3.0, I am getting the following error:
Something might have broken. Are you seeing any issue? I am still on Angular 8.0. Could this have been the issue? UPDATE 1: For now I added However, deserializeObject() method gives be a non-empty object but with all properties equal to null. Am I missing something here? |
@sagunpandey this has nothing to do with the PR, it is caused by the TypeScript update. The only possibility is probably to downgrade in json2typescript itself. Please let's discuss it in a separate issue. |
@andreas-aeschlimann Oops sorry I missed your comment earlier! You're right actually, it should have been object/object[] rather than any - to be honest I just didn't think of it. Sorry about that! I can submit a new pull request with that change if you like. Thanks for accepting this, and for updating the docs!! |
No worries. If you have time, you can do a PR. Otherwise I will fix it in a later commit. |
@cmolodo you might find it funny, but today I ran into a case where I thought that we need a third option for the I have strict mode enabled, but some properties may be null or primitive. When the server sends null for a primitive property, deserialization succeeds because I mark the property optional. However, when I want to serialize, the property is dropped. I rather send null values back to the server so the server knows that I actually want to set the value to null. We could add a third option for What do you think? |
@cmolodo let's continue the discussion about the
Let's continue this discussion here: #137 |
I have a suggestion for this problem. Let's discuss here: #138 |
Reopening a pull request similar to #92 using a rebased branch.
This includes 2 new features:
These are both features needed to support my specific use case. My data is represented by a nested structure of typescript classes with JSON mapping annotations. This data is filled in using Angular forms, which output a mix of pure JSON objects and typescript class objects, depending on the control values - I want to be able to send this data to the back end directly using my pre-defined mapping annotations. Additionally, because the data structure is large, users need to be able to edit portions of the data, and I want to serialize these patch objects without triggering an error due to other required properties not being present.
So these new features for me solve 2 problems:
As a trivial example, say I have the classes:
Together, these features let me serialize a patch edit object of the parent where I change the country without affecting the name property, and let me use the mappings defined on my classes to do so: