Any Protobuf guru's here? Have problem with outputted data.
-
I have an incoming json object that I can successfully deserialize into an object. However, I now need to send that object back to the UI and to do this we use Google Proto objects. This is what the json string looks like coming in and what it should look like going back out:
"lang\":{\"en-US\":{\"name\":\"AS Test Assembly Activity\",\"description\":\"Activity to test assembly activities\"}
I am trying to organize my proto messages that would output the same but I am having no luck. Here is what I have so far. Proto Messages:
message CustomActivityConfig { optional CustomActivityLanguage lang = 5; } message CustomActivityLanguage { required string key = 1; repeated LanguageData lang = 2; } message LanguageData { optional string name = 1; optional string description = 2; }
This gives me an output of:
"lang":{"key":"en-US","lang":[{"name":"AS Test Assembly Activity","description":"Activity to test assembly activities"}
My Class structure which holds the correct data from the json at the top looks like this:
\[Serializable\] public class CustomAssemblyData { public Dictionary<string, LangData> Lang { get; set; } } \[Serializable\] public class LangData { public string Name { get; set; } public string Description { get; set; } }
So what I am doing is iterating through the KeyValuePair in my class above and trying to pack it into my proto message. I feel if I can get the proto right that it should work as expected If this helps, here is how I am currently trying to pack the proto (which gives the second incorrect json output:
var cac = new CustomActivityConfig.Builder(); foreach (KeyValuePair<string, LangData> kvp in genericAssembly.CustomActivityConfig.Lang) { var culture = kvp.Key; var name = kvp.Value.Name; var desc = kvp.Value.Description; var langData = new LanguageData.Builder() { Name = name, Description = desc }.Build(); var customActivityLanguage = new CustomActivityLanguage.Builder() { Key = culture //will be 'en-US' in json }; //Add class to Value of Dictionary customActivityLanguage.AddLa
-
I have an incoming json object that I can successfully deserialize into an object. However, I now need to send that object back to the UI and to do this we use Google Proto objects. This is what the json string looks like coming in and what it should look like going back out:
"lang\":{\"en-US\":{\"name\":\"AS Test Assembly Activity\",\"description\":\"Activity to test assembly activities\"}
I am trying to organize my proto messages that would output the same but I am having no luck. Here is what I have so far. Proto Messages:
message CustomActivityConfig { optional CustomActivityLanguage lang = 5; } message CustomActivityLanguage { required string key = 1; repeated LanguageData lang = 2; } message LanguageData { optional string name = 1; optional string description = 2; }
This gives me an output of:
"lang":{"key":"en-US","lang":[{"name":"AS Test Assembly Activity","description":"Activity to test assembly activities"}
My Class structure which holds the correct data from the json at the top looks like this:
\[Serializable\] public class CustomAssemblyData { public Dictionary<string, LangData> Lang { get; set; } } \[Serializable\] public class LangData { public string Name { get; set; } public string Description { get; set; } }
So what I am doing is iterating through the KeyValuePair in my class above and trying to pack it into my proto message. I feel if I can get the proto right that it should work as expected If this helps, here is how I am currently trying to pack the proto (which gives the second incorrect json output:
var cac = new CustomActivityConfig.Builder(); foreach (KeyValuePair<string, LangData> kvp in genericAssembly.CustomActivityConfig.Lang) { var culture = kvp.Key; var name = kvp.Value.Name; var desc = kvp.Value.Description; var langData = new LanguageData.Builder() { Name = name, Description = desc }.Build(); var customActivityLanguage = new CustomActivityLanguage.Builder() { Key = culture //will be 'en-US' in json }; //Add class to Value of Dictionary customActivityLanguage.AddLa
What are you actually using to build the protobuf? Are you using Jon Skeet's implementation[^]?
-
What are you actually using to build the protobuf? Are you using Jon Skeet's implementation[^]?
I believe that is what we are using but am not 100% on it. Reason being is that the implementation is a part of our framework here and we don't touch it but rather implement it. I cannot be certain how the core framework is using it. I've determined that the 'dataType' so to speak is a Dictionary and that will allow me to deserialize the json into an object correctly. When it comes into my area it is a json, I deserialize into a class, now I need to pack it back into a proto and send it out in the exact same format it comes in at. I can't seem to order my proto in a way that does this.