Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
import com.iemr.common.data.notification.Notification;
import com.iemr.common.repository.callhandling.IEMRCalltypeRepositoryImplCustom;
import com.iemr.common.utils.exception.IEMRException;
import com.iemr.common.utils.mapper.CallTypeMapper;
import com.iemr.common.utils.mapper.InputMapper;

@Service
public class CalltypeServiceImpl implements CalltypeService
{
public class CalltypeServiceImpl implements CalltypeService {

@Autowired
private CallTypeMapper callTypeMapper;

private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
InputMapper inputMapper = new InputMapper();
Expand All @@ -55,9 +58,8 @@ public class CalltypeServiceImpl implements CalltypeService
private IEMRCalltypeRepositoryImplCustom iEMRCalltypeRepositoryImplCustom;

@Override
public List<CallType> getAllCalltypes(String request) throws IEMRException
{
CallType provider = inputMapper.gson().fromJson(request, CallType.class);
public List<CallType> getAllCalltypes(String request) throws IEMRException {
CallType provider = callTypeMapper.fromJson(request, CallType.class);
List<CallType> callTypes = new ArrayList<CallType>();
Set<Object[]> callTypesArray = new HashSet<Object[]>();
if (provider.getIsInbound() != null && provider.getIsOutbound() != null)
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/com/iemr/common/utils/mapper/CallTypeMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.iemr.common.utils.mapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@Service
public class CallTypeMapper {
private static GsonBuilder builder;
private static Gson gsonInstance;
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

public CallTypeMapper() {
if (builder == null) {
builder = new GsonBuilder();
// Only serialize/deserialize fields with @Expose annotation
builder.excludeFieldsWithoutExposeAnnotation();

logger.info("CallTypeMapper initialized - Only @Expose fields will be processed");
}
}

public static Gson gson() {
if (gsonInstance == null) {
gsonInstance = builder.create();
}
return gsonInstance;
}

public <T> T fromJson(String json, Class<T> classOfT) {
try {
T result = gson().fromJson(json, classOfT);
logger.info("Successfully deserialized to class: {}", classOfT.getSimpleName());
return result;
} catch (Exception e) {
logger.error("Error deserializing JSON to {}: {}", classOfT.getSimpleName(), e.getMessage(), e);
throw e;
}
}
}
Loading