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

Props prefixed with "Is" are not decoded #59

Closed
slipdef opened this issue May 21, 2022 · 3 comments
Closed

Props prefixed with "Is" are not decoded #59

slipdef opened this issue May 21, 2022 · 3 comments

Comments

@slipdef
Copy link

slipdef commented May 21, 2022

I translated this {"isFoo": true} to HEX here https://cbor.me/. It gave me this A1656973466F6FF5
Then I tried to decode it

public class Test
{
    public bool IsFoo { get; set; }
}

var test = CBORObject.DecodeFromBytes(Convert.FromHexString("A1656973466F6FF5")).ToObject<Test>();

And I got object with IsFoo false.

If I rename IsFoo to Foo all works well.

@peteroupc
Copy link
Owner

peteroupc commented Jun 4, 2022

Given the CBOR object {"isFoo": true}, rename the property public bool IsFoo { get; set; } to public bool IsIsFoo { get; set; }.

Also, to learn more about how the library maps property names to key names, see UseCamelCase in the documentation.

@slipdef
Copy link
Author

slipdef commented Jun 8, 2022

If "useCamelCase" is true :
In the .NET version, for each eligible property or field name, the word "Is" is removed from the name
if the name starts with that word, then the name is converted to camel case, 

What is the reason behind it?

@peteroupc
Copy link
Owner

The intent was to mimic, to some extent, the behavior in the Java version of the library (which uses a better established convention involving get, set, and is methods; see Corda, for example).

But as I've just found out, neither System.Text.Json nor Json.NET appear to treat property names starting with "Is" specially, compared to other property names. But my CBOR library does, hence the suggestion in my previous comment.

@slipdef slipdef closed this as completed Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants