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

FeatureManagement.FeatureDto.IStringValueType Cause Newtonsoft.Json.JsonSerializationException #4337

Closed
fenggaoyao opened this issue Jun 13, 2020 · 2 comments · Fixed by #4910
Assignees
Milestone

Comments

@fenggaoyao
Copy link

public interface IFeatureAppService : IApplicationService { Task<FeatureListDto> GetAsync([NotNull] string providerName, [NotNull] string providerKey); }
the GetAsync method Return FeatureListDto that contains IStringValueType.
In a monolithic application,It work well. But In microservices,IFeatureAppService as IRemoteService, and the returned Json format result,The Client cannot be serialized,it cause Newtonsoft.Json.JsonSerializationException: Could not create an instance of type Volo.Abp.Validation.StringValues.IStringValueType. Type is an interface or abstract class and cannot be instantiated.

How to deal with it?

@hikalkan
Copy link
Member

Yes, that can be a problem we need to work on.

@hikalkan hikalkan modified the milestones: 3.0, 3.1 Jun 30, 2020
@hikalkan hikalkan assigned maliming and unassigned hikalkan Jul 28, 2020
@hikalkan
Copy link
Member

hikalkan commented Jul 28, 2020

@maliming this problem really happens and I think there are two possible solutions:

  1. Completely change the DTOs and eleminate inheritance. This would be a breaking change.
  2. Write a custom JSON converter to manually deserialize the objects.

I prefer the 2nd option. If we write a custom deserializer, we can convert the following JSON:

{
  "features": [
    {
      "name": "MyProjectName.Feature1",
      "displayName": "MyProjectName.Feature1",
      "value": "B",
      "description": null,
      "valueType": {
        "itemSource": {
          "items": [
            {
              "value": "A",
              "displayText": {
                "resourceName": "MyProjectName",
                "name": "AKey"
              }
            },
            {
              "value": "B",
              "displayText": {
                "resourceName": "MyProjectName",
                "name": "BKey"
              }
            }
          ]
        },
        "name": "SelectionStringValueType",
        "properties": {},
        "validator": {
          "name": "NULL",
          "properties": {}
        }
      },
      "depth": 0,
      "parentName": null
    }
  ]
}

"name": "SelectionStringValueType" helps us to find the correct value type class.
"validator"."name": "NULL" helps us to find the correct validator class.
I know, writing hard-coded classes will not be so extensible, but we need to find a quick solution. We, later try to extend it.

Can you please work on that? If you have any question, please write to me.

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

Successfully merging a pull request may close this issue.

3 participants