Skip to content
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

Support collapsing single property classes #5

Closed
wants to merge 1 commit into from

Conversation

simensen
Copy link

Is this is something you are interested in? If not, I can fork. Otherwise, if you are interested but want some changes, I'm open. Let me know and I'll see what I can do!

For example, given the following JSON with ItemId, Name, and TimeZone all implementing CollapseToSingleValue, with this change the serialized JSON would flatten the resulting object to a string value.

Before this change:

{
    "itemId": {
        "uuid": "57D44FEF-C6E6-4908-B43D-76AF8295D06A"
    },
    "name": {
        "value": "elephpant"
    },
    "timestamp": {
        "secondsSinceUnixEpoch": 100,
        "timeZone": {
            "value": "UTC"
        }
    }
}

After this change:

{
    "itemId": "57D44FEF-C6E6-4908-B43D-76AF8295D06A",
    "name": "elephpant",
    "timestamp": {
        "secondsSinceUnixEpoch": 100,
        "timeZone": "UTC"
    }
}

For example, given the following JSON with ItemId, Name, and TimeZone
all implementing CollapseToSingleValue, with this change the
serialized JSON would flatten the resulting object to a
string value.

Before this change:

```
{
    "itemId": {
        "uuid": "57D44FEF-C6E6-4908-B43D-76AF8295D06A"
    },
    "name": {
        "value": "elephpant"
    },
    "timestamp": {
        "secondsSinceUnixEpoch": 100,
        "timeZone": {
            "value": "UTC"
        }
    }
}
```

After this change:

```
{
    "itemId": "57D44FEF-C6E6-4908-B43D-76AF8295D06A",
    "name": "elephpant",
    "timestamp": {
        "secondsSinceUnixEpoch": 100,
        "timeZone": "UTC"
    }
}
```
@simensen
Copy link
Author

@matthiasnoback You can feel free to close this if you aren't interested in this. :) Otherwise, let me know what you'd like to see happen to accept this PR and I'll see about fixing it!

@matthiasnoback
Copy link
Owner

Hey @simensen, for me this still doesn't really fit with this library's philosophy. I really want to keep it small, and base it on a minimum of assumptions. The main issues I have with collapsing properties:

  • It will be hard to migrate from collapsed properties to full objects (or back). But since it's completely optional, you could say the decision is on the user, and they will carry that burden ;)
  • Having an extra interface does not correspond to this library's philosophy that you shouldn't need anything else than your object, regular @var annotations, and the serializer. Once we add an interface, the object will not be "just your object" anymore. But this may not be that bad...

I'm aware that these limitations may make this library harder to work with, but it's also only meant to be used in the simplest of cases (actually, I created it just for workshops where we needed a very simple serializer, but one that knows about classes and properties). For production applications, I usually end up writing my own mapping code anyway.

I hope you won't be mad and we can still be friends ;)

@simensen simensen closed this Nov 13, 2019
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.

2 participants