MapsterMapper / MapsterMapper/Mapster

Mapster.JsonNet does not support Enum to string mapping

Open
#502 0 comments 0 reactions 1 assignee View on GitHub

@andrerav is already working on this.

Since Jan 11, 2023.

bug
Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

The following code attempts to map a JObject to a string.
However, the result yields the enum's int value instead of its name.

       //...
        typeAdapter.EnableJsonMapping();
        dynamic model = new JObject();
        model.enumValue = DomainEnum.Three;      
        var result = mapper.Map<string>(model);  // {  "enumValue": 2 }
  • Setting up typeAdapter.Default.EnumMappingStrategy(EnumMappingStrategy.ByName) did not change the result
  • Setting up the default serializer settings to use StringEnumConverter did not change the result
  • Using the attribute [JsonConverter(typeof(StringEnumConverter))] on the enum did not change the result

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.