Use of JsonIgnoreProperties specific property deserialize properties exists only in JSON
up vote
3
down vote
favorite
I stumbled upon some code that adds JsonIgnoreProperties to a property that doesn't exists in class, but exists in JSON
, e.g.:
@JsonIgnoreProperties({"ignoreprop"})
public class VO {
public String prop;
}
When JSON
is
{ "prop":"1", "ignoreprop":"9999"}
I wonder if ignoring properties has any advantage(s) performance-wise or is it just redundant code?
Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).
EDIT
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?
java json json-deserialization
add a comment |
up vote
3
down vote
favorite
I stumbled upon some code that adds JsonIgnoreProperties to a property that doesn't exists in class, but exists in JSON
, e.g.:
@JsonIgnoreProperties({"ignoreprop"})
public class VO {
public String prop;
}
When JSON
is
{ "prop":"1", "ignoreprop":"9999"}
I wonder if ignoring properties has any advantage(s) performance-wise or is it just redundant code?
Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).
EDIT
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?
java json json-deserialization
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I stumbled upon some code that adds JsonIgnoreProperties to a property that doesn't exists in class, but exists in JSON
, e.g.:
@JsonIgnoreProperties({"ignoreprop"})
public class VO {
public String prop;
}
When JSON
is
{ "prop":"1", "ignoreprop":"9999"}
I wonder if ignoring properties has any advantage(s) performance-wise or is it just redundant code?
Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).
EDIT
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?
java json json-deserialization
I stumbled upon some code that adds JsonIgnoreProperties to a property that doesn't exists in class, but exists in JSON
, e.g.:
@JsonIgnoreProperties({"ignoreprop"})
public class VO {
public String prop;
}
When JSON
is
{ "prop":"1", "ignoreprop":"9999"}
I wonder if ignoring properties has any advantage(s) performance-wise or is it just redundant code?
Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).
EDIT
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?
java json json-deserialization
java json json-deserialization
edited Nov 20 at 9:36
asked Nov 20 at 8:52
user7294900
19.6k93157
19.6k93157
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
I wonder if ignoring properties has any advantage
Yes, it is used a lot for forward-compatibility in services. Let's say you have Services A and B. Currently A sends requests to B with some JSON objects.
Now you want to support a new property in the JSON. If you have this feature you are able to let A start sending the new property before B knows how to handle it. Decoupling the development processes of those two services.
ignoring specific property over all
This case does have some minor performance advantages. First, it doesn't try to parse this property which can be a simple string or complex object/array. Second, it helps you avoid handling an exception. Think that all the following can be valid calls and you only care about prop
:
{ "prop":"1", "ignoreprop":"9999"}
{ "prop":"1", "ignoreprop":{ "a": { "key": "value", "foo": false }}}
{ "prop":"1", "ignoreprop":[1,2,3,4,5,6..... 1000000]}
1
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
SoignoreUnknown
will try to parse insideignoreprop
although it's not a property in class?
– user7294900
Nov 20 at 9:53
add a comment |
up vote
1
down vote
From the documentation, mainly the purpose of use this is To ignore any unknown properties in JSON input without exception: which is better not to popup exception when properties are not found either in class or JSON, and this might helps serializing faster docs
Example:
// to prevent specified fields from being serialized or deserialized
// (i.e. not include in JSON output; or being set even if they were included)
@JsonIgnoreProperties({ "internalId", "secretKey" })
// To ignore any unknown properties in JSON input without exception:
@JsonIgnoreProperties(ignoreUnknown=true)
Starting with 2.0, this annotation can be applied both to classes and to properties. If used for both, actual set will be union of all ignorals: that is, you can only add properties to ignore, not remove or override. So you can not remove properties to ignore using per-property annotation.
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
yes you can add all of them in annotation or simply add this@JsonIgnoreProperties(ignoreUnknown=true)
i will recommendunknown=true
in case of multiple properties
– Deadpool
Nov 20 at 9:22
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to setignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900
– Deadpool
Nov 20 at 9:30
I just want to know if there's a real reason/advantage to ignore specific property whenignoreUnknown=true
should cover it (and will be flexible)
– user7294900
Nov 20 at 10:37
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389302%2fuse-of-jsonignoreproperties-specific-property-deserialize-properties-exists-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I wonder if ignoring properties has any advantage
Yes, it is used a lot for forward-compatibility in services. Let's say you have Services A and B. Currently A sends requests to B with some JSON objects.
Now you want to support a new property in the JSON. If you have this feature you are able to let A start sending the new property before B knows how to handle it. Decoupling the development processes of those two services.
ignoring specific property over all
This case does have some minor performance advantages. First, it doesn't try to parse this property which can be a simple string or complex object/array. Second, it helps you avoid handling an exception. Think that all the following can be valid calls and you only care about prop
:
{ "prop":"1", "ignoreprop":"9999"}
{ "prop":"1", "ignoreprop":{ "a": { "key": "value", "foo": false }}}
{ "prop":"1", "ignoreprop":[1,2,3,4,5,6..... 1000000]}
1
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
SoignoreUnknown
will try to parse insideignoreprop
although it's not a property in class?
– user7294900
Nov 20 at 9:53
add a comment |
up vote
2
down vote
I wonder if ignoring properties has any advantage
Yes, it is used a lot for forward-compatibility in services. Let's say you have Services A and B. Currently A sends requests to B with some JSON objects.
Now you want to support a new property in the JSON. If you have this feature you are able to let A start sending the new property before B knows how to handle it. Decoupling the development processes of those two services.
ignoring specific property over all
This case does have some minor performance advantages. First, it doesn't try to parse this property which can be a simple string or complex object/array. Second, it helps you avoid handling an exception. Think that all the following can be valid calls and you only care about prop
:
{ "prop":"1", "ignoreprop":"9999"}
{ "prop":"1", "ignoreprop":{ "a": { "key": "value", "foo": false }}}
{ "prop":"1", "ignoreprop":[1,2,3,4,5,6..... 1000000]}
1
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
SoignoreUnknown
will try to parse insideignoreprop
although it's not a property in class?
– user7294900
Nov 20 at 9:53
add a comment |
up vote
2
down vote
up vote
2
down vote
I wonder if ignoring properties has any advantage
Yes, it is used a lot for forward-compatibility in services. Let's say you have Services A and B. Currently A sends requests to B with some JSON objects.
Now you want to support a new property in the JSON. If you have this feature you are able to let A start sending the new property before B knows how to handle it. Decoupling the development processes of those two services.
ignoring specific property over all
This case does have some minor performance advantages. First, it doesn't try to parse this property which can be a simple string or complex object/array. Second, it helps you avoid handling an exception. Think that all the following can be valid calls and you only care about prop
:
{ "prop":"1", "ignoreprop":"9999"}
{ "prop":"1", "ignoreprop":{ "a": { "key": "value", "foo": false }}}
{ "prop":"1", "ignoreprop":[1,2,3,4,5,6..... 1000000]}
I wonder if ignoring properties has any advantage
Yes, it is used a lot for forward-compatibility in services. Let's say you have Services A and B. Currently A sends requests to B with some JSON objects.
Now you want to support a new property in the JSON. If you have this feature you are able to let A start sending the new property before B knows how to handle it. Decoupling the development processes of those two services.
ignoring specific property over all
This case does have some minor performance advantages. First, it doesn't try to parse this property which can be a simple string or complex object/array. Second, it helps you avoid handling an exception. Think that all the following can be valid calls and you only care about prop
:
{ "prop":"1", "ignoreprop":"9999"}
{ "prop":"1", "ignoreprop":{ "a": { "key": "value", "foo": false }}}
{ "prop":"1", "ignoreprop":[1,2,3,4,5,6..... 1000000]}
edited Nov 20 at 9:37
answered Nov 20 at 9:23
Roee Gavirel
10.5k104272
10.5k104272
1
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
SoignoreUnknown
will try to parse insideignoreprop
although it's not a property in class?
– user7294900
Nov 20 at 9:53
add a comment |
1
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
SoignoreUnknown
will try to parse insideignoreprop
although it's not a property in class?
– user7294900
Nov 20 at 9:53
1
1
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?– user7294900
Nov 20 at 9:26
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?– user7294900
Nov 20 at 9:26
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
@user7294900 - edited to answer your specific question
– Roee Gavirel
Nov 20 at 9:38
So
ignoreUnknown
will try to parse inside ignoreprop
although it's not a property in class?– user7294900
Nov 20 at 9:53
So
ignoreUnknown
will try to parse inside ignoreprop
although it's not a property in class?– user7294900
Nov 20 at 9:53
add a comment |
up vote
1
down vote
From the documentation, mainly the purpose of use this is To ignore any unknown properties in JSON input without exception: which is better not to popup exception when properties are not found either in class or JSON, and this might helps serializing faster docs
Example:
// to prevent specified fields from being serialized or deserialized
// (i.e. not include in JSON output; or being set even if they were included)
@JsonIgnoreProperties({ "internalId", "secretKey" })
// To ignore any unknown properties in JSON input without exception:
@JsonIgnoreProperties(ignoreUnknown=true)
Starting with 2.0, this annotation can be applied both to classes and to properties. If used for both, actual set will be union of all ignorals: that is, you can only add properties to ignore, not remove or override. So you can not remove properties to ignore using per-property annotation.
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
yes you can add all of them in annotation or simply add this@JsonIgnoreProperties(ignoreUnknown=true)
i will recommendunknown=true
in case of multiple properties
– Deadpool
Nov 20 at 9:22
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to setignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900
– Deadpool
Nov 20 at 9:30
I just want to know if there's a real reason/advantage to ignore specific property whenignoreUnknown=true
should cover it (and will be flexible)
– user7294900
Nov 20 at 10:37
|
show 1 more comment
up vote
1
down vote
From the documentation, mainly the purpose of use this is To ignore any unknown properties in JSON input without exception: which is better not to popup exception when properties are not found either in class or JSON, and this might helps serializing faster docs
Example:
// to prevent specified fields from being serialized or deserialized
// (i.e. not include in JSON output; or being set even if they were included)
@JsonIgnoreProperties({ "internalId", "secretKey" })
// To ignore any unknown properties in JSON input without exception:
@JsonIgnoreProperties(ignoreUnknown=true)
Starting with 2.0, this annotation can be applied both to classes and to properties. If used for both, actual set will be union of all ignorals: that is, you can only add properties to ignore, not remove or override. So you can not remove properties to ignore using per-property annotation.
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
yes you can add all of them in annotation or simply add this@JsonIgnoreProperties(ignoreUnknown=true)
i will recommendunknown=true
in case of multiple properties
– Deadpool
Nov 20 at 9:22
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to setignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900
– Deadpool
Nov 20 at 9:30
I just want to know if there's a real reason/advantage to ignore specific property whenignoreUnknown=true
should cover it (and will be flexible)
– user7294900
Nov 20 at 10:37
|
show 1 more comment
up vote
1
down vote
up vote
1
down vote
From the documentation, mainly the purpose of use this is To ignore any unknown properties in JSON input without exception: which is better not to popup exception when properties are not found either in class or JSON, and this might helps serializing faster docs
Example:
// to prevent specified fields from being serialized or deserialized
// (i.e. not include in JSON output; or being set even if they were included)
@JsonIgnoreProperties({ "internalId", "secretKey" })
// To ignore any unknown properties in JSON input without exception:
@JsonIgnoreProperties(ignoreUnknown=true)
Starting with 2.0, this annotation can be applied both to classes and to properties. If used for both, actual set will be union of all ignorals: that is, you can only add properties to ignore, not remove or override. So you can not remove properties to ignore using per-property annotation.
From the documentation, mainly the purpose of use this is To ignore any unknown properties in JSON input without exception: which is better not to popup exception when properties are not found either in class or JSON, and this might helps serializing faster docs
Example:
// to prevent specified fields from being serialized or deserialized
// (i.e. not include in JSON output; or being set even if they were included)
@JsonIgnoreProperties({ "internalId", "secretKey" })
// To ignore any unknown properties in JSON input without exception:
@JsonIgnoreProperties(ignoreUnknown=true)
Starting with 2.0, this annotation can be applied both to classes and to properties. If used for both, actual set will be union of all ignorals: that is, you can only add properties to ignore, not remove or override. So you can not remove properties to ignore using per-property annotation.
edited Nov 20 at 9:20
answered Nov 20 at 9:03
Deadpool
3,2972324
3,2972324
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
yes you can add all of them in annotation or simply add this@JsonIgnoreProperties(ignoreUnknown=true)
i will recommendunknown=true
in case of multiple properties
– Deadpool
Nov 20 at 9:22
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to setignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900
– Deadpool
Nov 20 at 9:30
I just want to know if there's a real reason/advantage to ignore specific property whenignoreUnknown=true
should cover it (and will be flexible)
– user7294900
Nov 20 at 10:37
|
show 1 more comment
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
yes you can add all of them in annotation or simply add this@JsonIgnoreProperties(ignoreUnknown=true)
i will recommendunknown=true
in case of multiple properties
– Deadpool
Nov 20 at 9:22
Is there an advantage(s) ignoring specific property over all (with@JsonIgnoreProperties(ignoreUnknown=true)
)?
– user7294900
Nov 20 at 9:26
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to setignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900
– Deadpool
Nov 20 at 9:30
I just want to know if there's a real reason/advantage to ignore specific property whenignoreUnknown=true
should cover it (and will be flexible)
– user7294900
Nov 20 at 10:37
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
Can you add link to doc? If I want to ignore dozen of properties is it still better?
– user7294900
Nov 20 at 9:18
yes you can add all of them in annotation or simply add this
@JsonIgnoreProperties(ignoreUnknown=true)
i will recommend unknown=true
in case of multiple properties– Deadpool
Nov 20 at 9:22
yes you can add all of them in annotation or simply add this
@JsonIgnoreProperties(ignoreUnknown=true)
i will recommend unknown=true
in case of multiple properties– Deadpool
Nov 20 at 9:22
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?– user7294900
Nov 20 at 9:26
Is there an advantage(s) ignoring specific property over all (with
@JsonIgnoreProperties(ignoreUnknown=true)
)?– user7294900
Nov 20 at 9:26
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to set
ignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900– Deadpool
Nov 20 at 9:30
lets get this straight, you get JSON with 100 fields, and you only need 5 fields, then is it recommended to set
ignoreUnknown=true)
or specify each field?, it complete depends on requirement, and this annotation completely avoids exception with unknown fields that is main intention of this @user7294900– Deadpool
Nov 20 at 9:30
I just want to know if there's a real reason/advantage to ignore specific property when
ignoreUnknown=true
should cover it (and will be flexible)– user7294900
Nov 20 at 10:37
I just want to know if there's a real reason/advantage to ignore specific property when
ignoreUnknown=true
should cover it (and will be flexible)– user7294900
Nov 20 at 10:37
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389302%2fuse-of-jsonignoreproperties-specific-property-deserialize-properties-exists-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown