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

Ignore Field Names In Serialization #4

Open
sadradelir opened this issue Mar 28, 2017 · 4 comments
Open

Ignore Field Names In Serialization #4

sadradelir opened this issue Mar 28, 2017 · 4 comments
Labels

Comments

@sadradelir
Copy link

Can we ignore field names in serialization ? I use SerializationOptions.SuppressTypeInformation but i have my class members names in serialization.

@deniszykov
Copy link
Owner

Hi @sadradelir, if you want to ignore some field during serialization you could:
a) make them private|protected|internal
b) remove DataContractAttribute from class and add IgnoreDataMemberAttribute on ignored fields
c) add DataContractAttribute and mark with DataMemberAttribute only required fields, non-marked will be ignored.

@sadradelir
Copy link
Author

sadradelir commented Mar 28, 2017

Hi @deniszykov and thanks for your fast replay, But I mean field names not entire ignore of field, for example i pack this class :
{
public int test1 = 10 ;
public int test2 = 20 ;
}
and I got this :
"StringPrefix"test1"IntPrefix"10"StringPrefix"test2"IntPrefix"20
but with java library and msgPack-Cli ( standard version mentioned in msgpack.org for c# ) we got this ( with field name ignorance ) :
"IntPrefix"10"IntPrefix"20

@deniszykov
Copy link
Owner

Do you mean storing only objects field values? At the moment there is no such feature. You can implement your own serializer of such objects and register it in SerializationContext.ObjectSerializerFactory.

var context = new SerializationContext();
context.ObjectSerializerFactory = (t => 
    IsSpecialType(t) ? 
         new SpecialTypeSerializer(t) : 
         new ObjectSerializer(context, t)
);

@sadradelir
Copy link
Author

yes I mean this, so I should develop my serilizerFactory, thanks for your fast answer. and I appreciate your help :) .

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

No branches or pull requests

2 participants