We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package com.app.security
class AuthUser { String username String password }
package com.app.utils.gson
import com.app.security.AuthUser import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonSerializationContext import com.google.gson.JsonSerializer
import java.lang.reflect.Type
class AuthUserSerializer implements JsonSerializer {
public AuthUserSerializer() { super(); }
JsonElement serialize(AuthUser value, Type type, JsonSerializationContext context) { final JsonObject jsonObj = new JsonObject();
['id', 'username'].each { jsonObj.add(it, context.serialize(value[it])) } return jsonObj;
} }
...In BootStrap...
def gsonBuilder def init = { servletContext -> gsonBuilder.registerTypeAdapter(AuthUser.class, new AuthUserSerializer()); }
...In Controller... def authUser = new AuthUser(username:"someuser", password:"NOT SUPPOSED TO SHOW").save()
// Works fine render (authUser as GSON) // = {"id":2, "username":"someuser"}
// Serializer not leveraged render ([profile:memberService.currentMember] as GSON) // = {"profile":{"id":2, "username":"someuser", "password":"NOT SUPPOSED TO SHOW"}}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
package com.app.security
class AuthUser {
String username
String password
}
package com.app.utils.gson
import com.app.security.AuthUser
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import java.lang.reflect.Type
class AuthUserSerializer implements JsonSerializer {
public AuthUserSerializer() {
super();
}
JsonElement serialize(AuthUser value, Type type, JsonSerializationContext context) {
final JsonObject jsonObj = new JsonObject();
}
}
...In BootStrap...
def gsonBuilder
def init = { servletContext ->
gsonBuilder.registerTypeAdapter(AuthUser.class, new AuthUserSerializer());
}
...In Controller...
def authUser = new AuthUser(username:"someuser", password:"NOT SUPPOSED TO SHOW").save()
// Works fine
render (authUser as GSON) // = {"id":2, "username":"someuser"}
// Serializer not leveraged
render ([profile:memberService.currentMember] as GSON) // = {"profile":{"id":2, "username":"someuser", "password":"NOT SUPPOSED TO SHOW"}}
The text was updated successfully, but these errors were encountered: