feat(util): JsonUtil.normalizeEvaluation — 평문→JSON 래핑 + 300자 제한
- evaluation 컬럼이 IS JSON 제약이라 평문은 {"text":"..."}로 정규화
- parseMap이 잘못된 JSON 받았을 때 빈 Map 대신 {"text":원문}으로 보존
- PipelineService/RestaurantService에서 이미 호출 중인 유틸 — 미커밋 상태였음
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,8 @@ public final class JsonUtil {
|
||||
try {
|
||||
return MAPPER.readValue(json, new TypeReference<>() {});
|
||||
} catch (Exception e) {
|
||||
return Collections.emptyMap();
|
||||
// Plain text or malformed JSON (e.g. Python-style single quotes) → wrap as {"text": "..."}
|
||||
return Map.of("text", json.trim());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +75,24 @@ public final class JsonUtil {
|
||||
return rows.stream().map(JsonUtil::lowerKeys).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize evaluation to a valid JSON object string (e.g. {"text":"..."}).
|
||||
* Plain text is wrapped, already-valid JSON is returned as-is, and text is truncated to maxLen.
|
||||
*/
|
||||
public static String normalizeEvaluation(String eval, int maxLen) {
|
||||
if (eval == null || eval.isBlank()) return null;
|
||||
String trimmed = eval.trim();
|
||||
if (trimmed.startsWith("{")) return trimmed;
|
||||
if (trimmed.length() > maxLen) {
|
||||
trimmed = trimmed.substring(0, maxLen);
|
||||
}
|
||||
return toJson(Map.of("text", trimmed));
|
||||
}
|
||||
|
||||
public static String normalizeEvaluation(String eval) {
|
||||
return normalizeEvaluation(eval, 300);
|
||||
}
|
||||
|
||||
public static String toJson(Object value) {
|
||||
try {
|
||||
return MAPPER.writeValueAsString(value);
|
||||
|
||||
Reference in New Issue
Block a user