Java tutorial
package tv.arte.resteventapi.core.presentation.view; /* * #%L * RestEventAPI * %% * Copyright (C) 2014 ARTE G.E.I.E * %% * This program is free software: you can redistribute it and/or modify * it under the terms of The MIT License (MIT) as published by the Open Source * Initiative. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See The * MIT License (MIT) for more details. * * You should have received a copy of The MIT License (MIT) * along with this program. If not, see <http://opensource.org/licenses/MIT> * #L% */ import java.util.HashMap; import java.util.Map; import org.springframework.web.servlet.view.json.MappingJackson2JsonView; import tv.arte.resteventapi.core.presentation.serialization.Stripped; import tv.arte.resteventapi.core.presentation.serialization.TransientString; /** * Provide some custom rendering features * * @author Simeon Petev * @since 0.1 */ public class MappingRestEventApi2JsonView extends MappingJackson2JsonView { public MappingRestEventApi2JsonView() { super(); } /** * Transforms */ @SuppressWarnings("unchecked") @Override protected Object filterModel(Map<String, Object> model) { Object resultSuper = super.filterModel(model); if (resultSuper instanceof Map) { Map<Object, Object> result = new HashMap<Object, Object>(); for (Map.Entry<String, Object> entry : ((Map<String, Object>) resultSuper).entrySet()) { if (entry.getValue().getClass().getAnnotation(Stripped.class) == null) { result.put(entry.getKey(), entry.getValue()); } else { result.put(new TransientString(entry.getKey()), entry.getValue()); } } return result; } else { return resultSuper; } } }