Skip to content

Modify/extend objects at runtime #24

Description

@bmmptlgc

I need modify/extend objects at runtime. For example,

I want to extend an Order object returned by an API, so that the serialized JSON response would go from:

{
	"orderId": "abc",
	"price": 100,
	"orderItems": [
		{
			"orderItemId": "def",
			"price": 55
		},
		{
			"orderItemId": "ghi",
			"price": 45
		}
	]
}

to:

{
	"@id": "https://someurl/api/orders/abc",
	"orderId": "abc",
	"price": 100,
	"orderItems": [
		{
			"@id": "https://someurl/api/orders/abc/order-item/def",
			"orderItemId": "def",
			"price": 55
		},
		{
			"@id": "https://someurl/api/orders/abc/order-item/ghi",
			"orderItemId": "ghi",
			"price": 45
		}
	]
}

I am able to accomplish this using reflection, but was wondering if I can simplify the code with fasterflect.

Essentially, I need to an Id field to OrderItem with a JsonPropertyName attribute with the value "@id". I need to do the same thing to the Order object, plus add a couple more fields I didn't include in the example above, for simplicity.

Can fasterflect do this?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions