Bind data to java object












1















I am trying to integrate a service in my system. which send the data in



below format



id=c100610414&amount=4681&card_currency_code=INR&transaction_ref_no=c1006f9bc12d411


I wish to bind it in java bean object in a performance effective manner.
Below is the code I have done so far



String splitval = val.split("&");

JSONObject json = new JSONObject();
for (int i = 0; i < splitval.length; i++) {
String _split = splitval[i].split("=");
if (_split.length > 1)
json.put(_split[0].trim(), _split[1].trim());
}
prePaidCardTxnBean = new Gson().fromJson(json.toString(), CardBean.class);









share|improve this question























  • and...? any problems?

    – Scary Wombat
    Nov 26 '18 at 0:23








  • 2





    belongs to codereview.stackexchange.com

    – Kartik
    Nov 26 '18 at 0:28











  • The code works fine, however I wish to know if it can be improved further as its important for my use case

    – abhi314
    Nov 26 '18 at 0:30











  • Premature optimization is bad. Just make whatever you are making work and see if its within SLAs or performant for the use case its meeting. Given you are working with other services your I/O will be your biggest performance sink in general. Not splitting a string.

    – Darren Forsythe
    Nov 26 '18 at 0:42











  • Of course, converting some trivial strings into JSON, just to parse them afterwards, is everything but efficient. You are already looping over all properties and splitting them into name and value, so all you have to do, is to check the names and set the particular property on the target object.

    – Holger
    Nov 28 '18 at 8:18
















1















I am trying to integrate a service in my system. which send the data in



below format



id=c100610414&amount=4681&card_currency_code=INR&transaction_ref_no=c1006f9bc12d411


I wish to bind it in java bean object in a performance effective manner.
Below is the code I have done so far



String splitval = val.split("&");

JSONObject json = new JSONObject();
for (int i = 0; i < splitval.length; i++) {
String _split = splitval[i].split("=");
if (_split.length > 1)
json.put(_split[0].trim(), _split[1].trim());
}
prePaidCardTxnBean = new Gson().fromJson(json.toString(), CardBean.class);









share|improve this question























  • and...? any problems?

    – Scary Wombat
    Nov 26 '18 at 0:23








  • 2





    belongs to codereview.stackexchange.com

    – Kartik
    Nov 26 '18 at 0:28











  • The code works fine, however I wish to know if it can be improved further as its important for my use case

    – abhi314
    Nov 26 '18 at 0:30











  • Premature optimization is bad. Just make whatever you are making work and see if its within SLAs or performant for the use case its meeting. Given you are working with other services your I/O will be your biggest performance sink in general. Not splitting a string.

    – Darren Forsythe
    Nov 26 '18 at 0:42











  • Of course, converting some trivial strings into JSON, just to parse them afterwards, is everything but efficient. You are already looping over all properties and splitting them into name and value, so all you have to do, is to check the names and set the particular property on the target object.

    – Holger
    Nov 28 '18 at 8:18














1












1








1








I am trying to integrate a service in my system. which send the data in



below format



id=c100610414&amount=4681&card_currency_code=INR&transaction_ref_no=c1006f9bc12d411


I wish to bind it in java bean object in a performance effective manner.
Below is the code I have done so far



String splitval = val.split("&");

JSONObject json = new JSONObject();
for (int i = 0; i < splitval.length; i++) {
String _split = splitval[i].split("=");
if (_split.length > 1)
json.put(_split[0].trim(), _split[1].trim());
}
prePaidCardTxnBean = new Gson().fromJson(json.toString(), CardBean.class);









share|improve this question














I am trying to integrate a service in my system. which send the data in



below format



id=c100610414&amount=4681&card_currency_code=INR&transaction_ref_no=c1006f9bc12d411


I wish to bind it in java bean object in a performance effective manner.
Below is the code I have done so far



String splitval = val.split("&");

JSONObject json = new JSONObject();
for (int i = 0; i < splitval.length; i++) {
String _split = splitval[i].split("=");
if (_split.length > 1)
json.put(_split[0].trim(), _split[1].trim());
}
prePaidCardTxnBean = new Gson().fromJson(json.toString(), CardBean.class);






java json performance bind






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 0:21









abhi314abhi314

68521240




68521240













  • and...? any problems?

    – Scary Wombat
    Nov 26 '18 at 0:23








  • 2





    belongs to codereview.stackexchange.com

    – Kartik
    Nov 26 '18 at 0:28











  • The code works fine, however I wish to know if it can be improved further as its important for my use case

    – abhi314
    Nov 26 '18 at 0:30











  • Premature optimization is bad. Just make whatever you are making work and see if its within SLAs or performant for the use case its meeting. Given you are working with other services your I/O will be your biggest performance sink in general. Not splitting a string.

    – Darren Forsythe
    Nov 26 '18 at 0:42











  • Of course, converting some trivial strings into JSON, just to parse them afterwards, is everything but efficient. You are already looping over all properties and splitting them into name and value, so all you have to do, is to check the names and set the particular property on the target object.

    – Holger
    Nov 28 '18 at 8:18



















  • and...? any problems?

    – Scary Wombat
    Nov 26 '18 at 0:23








  • 2





    belongs to codereview.stackexchange.com

    – Kartik
    Nov 26 '18 at 0:28











  • The code works fine, however I wish to know if it can be improved further as its important for my use case

    – abhi314
    Nov 26 '18 at 0:30











  • Premature optimization is bad. Just make whatever you are making work and see if its within SLAs or performant for the use case its meeting. Given you are working with other services your I/O will be your biggest performance sink in general. Not splitting a string.

    – Darren Forsythe
    Nov 26 '18 at 0:42











  • Of course, converting some trivial strings into JSON, just to parse them afterwards, is everything but efficient. You are already looping over all properties and splitting them into name and value, so all you have to do, is to check the names and set the particular property on the target object.

    – Holger
    Nov 28 '18 at 8:18

















and...? any problems?

– Scary Wombat
Nov 26 '18 at 0:23







and...? any problems?

– Scary Wombat
Nov 26 '18 at 0:23






2




2





belongs to codereview.stackexchange.com

– Kartik
Nov 26 '18 at 0:28





belongs to codereview.stackexchange.com

– Kartik
Nov 26 '18 at 0:28













The code works fine, however I wish to know if it can be improved further as its important for my use case

– abhi314
Nov 26 '18 at 0:30





The code works fine, however I wish to know if it can be improved further as its important for my use case

– abhi314
Nov 26 '18 at 0:30













Premature optimization is bad. Just make whatever you are making work and see if its within SLAs or performant for the use case its meeting. Given you are working with other services your I/O will be your biggest performance sink in general. Not splitting a string.

– Darren Forsythe
Nov 26 '18 at 0:42





Premature optimization is bad. Just make whatever you are making work and see if its within SLAs or performant for the use case its meeting. Given you are working with other services your I/O will be your biggest performance sink in general. Not splitting a string.

– Darren Forsythe
Nov 26 '18 at 0:42













Of course, converting some trivial strings into JSON, just to parse them afterwards, is everything but efficient. You are already looping over all properties and splitting them into name and value, so all you have to do, is to check the names and set the particular property on the target object.

– Holger
Nov 28 '18 at 8:18





Of course, converting some trivial strings into JSON, just to parse them afterwards, is everything but efficient. You are already looping over all properties and splitting them into name and value, so all you have to do, is to check the names and set the particular property on the target object.

– Holger
Nov 28 '18 at 8:18












0






active

oldest

votes











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',
autoActivateHeartbeat: false,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473355%2fbind-data-to-java-object%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473355%2fbind-data-to-java-object%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen