From c784df964e29c245d5b4bc311607ff1cf6b094d9 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 27 Jul 2017 17:17:49 +0200 Subject: [PATCH] #594 - Polishing. Rather use early return for null annotation instead of conditional lookup. Original pull request: #595. --- .../hateoas/core/AnnotationMappingDiscoverer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/core/AnnotationMappingDiscoverer.java b/src/main/java/org/springframework/hateoas/core/AnnotationMappingDiscoverer.java index 18141fca..2b6f1555 100644 --- a/src/main/java/org/springframework/hateoas/core/AnnotationMappingDiscoverer.java +++ b/src/main/java/org/springframework/hateoas/core/AnnotationMappingDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,12 +108,12 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { private String[] getMappingFrom(Annotation annotation) { - Object value = null; - - if (annotation != null) { - value = mappingAttributeName == null ? getValue(annotation) : getValue(annotation, mappingAttributeName); + if (annotation == null) { + return new String[0]; } + Object value = mappingAttributeName == null ? getValue(annotation) : getValue(annotation, mappingAttributeName); + if (value instanceof String) { return new String[] { (String) value }; } else if (value instanceof String[]) {