java


Export a JSON sub-node without creating a new class?


If I want to export JSON of this structure, do I need 3 classes as in the following code? Can I use Jackson, or a different framework, to accomplish this in once class?
Also, does this seem like an unnecessary amount of boilerplate to produce some JSON (the actual JSON object is similar but has a lot more key/value pairs), or is this is an appropriate strategy?
{
"object1":{
"key1":"value1",
"object2":{
"key2":"value2"
}
},
"key3":"value3"
}
public class JsonProducer {
#JsonProperty("object1")
Object1 getObject1() {
return new Object1();
}
#JsonProperty("key3")
String getKey3() {
return "value3"
}
class Object1 {
#JsonProperty("key1")
String getKey1() {
return "value1";
}
#JsonProperty("object2")
Object2 getObject2() {
return new Object2();
}
}
class Object2 {
#JsonProperty("key2")
String getKey2() {
return "value2";
}
}
}

Related Links

Spring-boot automatically import applicationContext.xml?
Class com.google.appengine.tools.development.agent.runtime.Runtime can not access a member of class
Cannot resolve symbol error even tho everything works fine (IntelliJ IDEA)
How do I get out of this freaking loop
Java if+String dont work together [duplicate]
Reading short from byte array
no persistence provider for EntityManager named persistence.xml
Where should reside the logic to assemble the domain object from DAO?
securesocial.core.Identity missing from SecureSocial library?
What does Strictfp means in java?
Strange output(square symbol) in the Java code
IabHelper launchPurchaseFlow google play In-app Billing does not find product
ā€œSā€ symbol appearing on Maven Project
Decoding MJPEG stream using android BitmapFactory.decodeByteArray Garbage collection
Hibernate criteria group results by date from timestamp
Mapping multiple tables to one List Hibernate

Categories

HOME
pandas
bluetooth
hive
cloud
view
lodash
gps
callback
disassembler
constraint-programming
upload
python-unittest
izpack
zend-framework3
messages
try-catch
worldwind
openrefine
contextmenu
firefox-webextensions
autocad-plugin
web-sql
chromium-embedded
claims-based-identity
qhull
semantic-analysis
ping
msys2
quote
librato
junit5
http-status-code-503
contact-form
accelerate-framework
xcode-extension
twitch
hue
grid.mvc
vao
avconv
atomicity
pango
errordocument
rails-routing
integrity
mu
tropo
nativeapplication
feeds
typed-lambda-calculus
python-cryptography
gcsfuse
nbconvert
iso8601
account-kit
or-tools
objective-c-swift-bridge
deadbolt-2
heidisql
infix-notation
autorest
disque
superstack
angular-leaflet-directive
splash
operation
sniffer
sortedlist
device-orientation
nsmutabledictionary
operator-precedence
jscript.net
gui-test-framework
mesa
phpthumb
yorick
hippomocks
comexception
android-2.2-froyo
resty-gwt
xsockets.net
file-locking
excel-2003
shellexecute
wsdl-2.0
browser-detection
dmoz
windows-phone-7.1.1
netbeans-6.9
ohm
asyncfileupload
boost-filesystem
tomcat-valve
google-friend-connect
dentrix
icanhaz.js
ncqrs
thunderbird-lightning
yagni
aquaticprime
gacutil
scripting-languages

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App