Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.service.serialization

File DynamicResolvingMoxyJsonProvider.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
10
3
1
36
30
5
0.5
3.33
3
1.67

Classes

Class Line # Actions
DynamicResolvingMoxyJsonProvider 11 10 5
1.0100%
 

Contributing tests

This file is covered by 11 tests. .

Source view

1    package io.sunshower.service.serialization;
2   
3    import java.lang.reflect.Type;
4    import java.util.HashMap;
5    import java.util.HashSet;
6    import java.util.Map;
7    import java.util.Set;
8    import javax.ws.rs.ext.Providers;
9    import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
10   
 
11    public class DynamicResolvingMoxyJsonProvider extends MOXyJsonProvider {
12   
13    private final Map<Class<?>, Set<Class<?>>> registrations;
14   
 
15  2 toggle public DynamicResolvingMoxyJsonProvider(Providers providers) {
16  2 this.providers = providers;
17  2 this.registrations = new HashMap<>();
18    }
19   
 
20  77 toggle @Override
21    @SuppressWarnings("unchecked")
22    protected Set<Class<?>> getDomainClasses(Type genericType) {
23  77 if (genericType instanceof Class && registrations.containsKey(genericType)) {
24  14 final Set<Class<?>> classes = new HashSet(registrations.get(genericType));
25  14 classes.add((Class<?>) genericType);
26  14 classes.addAll(super.getDomainClasses(genericType));
27  14 return classes;
28    }
29  63 return super.getDomainClasses(genericType);
30    }
31   
 
32  1 toggle public <T> void register(Class<?> graphClass, Class<T> type) {
33  1 Set<Class<?>> classes = registrations.computeIfAbsent(graphClass, k -> new HashSet<>());
34  1 classes.add(type);
35    }
36    }