Serialize and deserialize Enum values as strings#64
Serialize and deserialize Enum values as strings#64jasonmead wants to merge 3 commits intofacebook-csharp-sdk:masterfrom
Conversation
|
this issue is not working in the current version. working on a fix to the code. |
|
|
Here the code change: Method:* public virtual object DeserializeObject(object value, Type type)* line: 1386Current version at time of change is 0.38.0 |
|
Submit a PR with tests, please. |
|
I have never done a PR request. reading up on google and going try it. |
|
I followed this: https://guides.github.com/activities/contributing-to-open-source/ I did the fork. made a branch (enumfix). compiled solution. updated source. committed branch. added tests (EnumTest). unsure what do to next. the code been committed to the branch. Everything compiles. test worked ok. checked in. |
|
The next step would be to open a pull request from your forked branch. |
|
@jasonmead this is great, i'm not sure what the diff between your PR and @amccorma PR #72 although that PR I think has line ending issues as the whole simplejson file has changed. I'd like to get this into Nancy https://github.com/NancyFx/Nancy for the JSON work you did. Including @prabirshrestha in this too. What needs to be done to get this feature in ASAP? |
added fix to this PR as described by @amccorma
|
This will have to be implemented in Nancy directly. Unfortunately, we had to modify SimpleJson.cs in Nancy to get it to work correctly. |
|
@jchannon I will be out of town. will have to look at this next week. |
|
What is the status? I need enum support to use SimpleJson in a Unity game (last stable version of which sadly provides us, programmers, with C# 4 and .NET 2.0-3.5 at the time of writing which don't make much of choise when handling json). It's the only thing, that stops me from using SimpleJson. I need something like this to work: [DataContract]
public enum Keeper
{
[DataMember(Name = "no keeper")]
None,
[DataMember(Name = "Mary Rose")]
Mary,
[DataMember(Name = "Tom The Third")]
Tom,
[DataMember(Name = "Simply, Todd")]
Todd
}
[DataContract]
public class Animal : JsonResponse
{
[NotNull]
[DataMember(Name = "animal color")] // works ok
public string Color { get; private set; }
[DataMember(Name = "animal keeper")] // fails, enum serialized as number ( 0 for None, 1 for Mary and so on)
public Keeper Keeper { get; private set; }
}So, needed serialized example of animal: Actual serialized example of animal: I came from java and there we successfully used (for example) com.google.api.client.util.Value attribute to specify [de]serialized string value for each enum member: public enum CardStatus {
@Value("active")
ACTIVE,
@Value("expired")
EXPIRED,
@Value("blocked")
BLOCKED
}
public class Card {
@Key("card id")
private String id;
@Key("status")
private CardStatus status;
}So, serialized example of Card: PS com.google.api.client.util.Value is in com.google.http-client:google-http-client-android:1.22.0 or com.google.http-client:google-http-client-jackson2:1.22.0 - don't remember exactly, allways imported both at the same time PS I tested code of that merge request and it gave me: |
Fixes #15