Tencent/APIJSON · error · ConflictException

${key}: value 中 ${tbl} 已经存在,不能重复!

Error message

${key}: value 中 ${tbl} 已经存在,不能重复!

What it means

When a METHOD directive ('INSERT', 'UPDATE', 'DELETE', 'POST'...) is given as a whitespace-separated String of table names, the parser builds a map from them; a name appearing twice produces this ConflictException because each table may be targeted only once per directive.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractParser.java:2317

		KEY_METHOD_ENUM_MAP.put(KEY_HEAD, RequestMethod.HEAD);
		KEY_METHOD_ENUM_MAP.put(KEY_HEADS, RequestMethod.HEADS);
		KEY_METHOD_ENUM_MAP.put(KEY_POST, RequestMethod.POST);
		KEY_METHOD_ENUM_MAP.put(KEY_PUT, RequestMethod.PUT);
		KEY_METHOD_ENUM_MAP.put(KEY_DELETE, RequestMethod.DELETE);
	}

	private void parseMethodDirective(String key, RequestMethod keyMethod, @NotNull M request) throws Exception {
		boolean isPost = KEY_POST.equals(key);
		Object val = request.get(key);
		Map<String, Object> obj = val instanceof Map<?, ?> ? JSON.get(request, key) : null;
		if (obj == null) {
			if (val instanceof String) {
				String[] tbls = StringUtil.split((String) val);
				if (tbls != null && tbls.length > 0) {
					obj = new LinkedHashMap<String, Object>();
					for (String tbl : tbls) {
						if (obj.containsKey(tbl)) {
							throw new ConflictException(key + ": value 中 " + tbl + " 已经存在,不能重复!");
						}

						obj.put(tbl, isPost && isTableArray(tbl)
								? tbl.substring(0, tbl.length() - 2) + ":[]" : "");
					}
				}
			}
			else {
				throw new IllegalArgumentException(key + ": value 中 value 类型错误,只能是 String 或 Map<String, Object> {} !");
			}
		}

		Set<Entry<String, Object>> set = obj == null ? new HashSet<>() : obj.entrySet();
		for (Entry<String, Object> objEntry : set) {
			String objKey = objEntry == null ? null : objEntry.getKey();
			if (objKey == null) {
				continue;
			}

View on GitHub (pinned to 5284052872)

Solutions

  1. Deduplicate the table list before sending: 'User, Comment' instead of 'User, User, Comment'
  2. If the same table needs two different operations, list it under the appropriate distinct directive keys

Example fix

// before
{ 'INSERT': 'User, User, Comment' }
// after
{ 'INSERT': 'User, Comment' }
Defensive patterns

Strategy: validation

Validate before calling

function dedupeMethodDirective(directive, value) {
  if (typeof value !== 'string') return value;
  const seen = new Set();
  const out = [];
  for (const t of value.split(/[\s,]+/).filter(Boolean)) {
    if (!seen.has(t)) { seen.add(t); out.push(t); }
  }
  if (out.length !== value.split(/[\s,]+/).filter(Boolean).length) {
    console.warn(`${directive}: duplicates removed -> ${out.join(', ')}`);
  }
  return out.join(', ');
}
// request[directive] = dedupeMethodDirective('INSERT', request['INSERT']);

Try / catch

Catch ConflictException containing '不能重复'; deduplicate the directive string and retry once.

Prevention

When it happens

Trigger: { 'INSERT': 'User, User' } or { 'POST': 'Moment Moment' } — duplicate tokens in the directive string (duplicates inside a Map value like { 'User': {}, 'User': {} } are impossible in JSON parsing, so the String form is the trigger).

Common situations: Concatenating table lists from multiple code paths without deduplicating; user-composed input where the same table is selected twice; trailing duplicates introduced by templating.

Related errors


AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14). Data as JSON: /api/errors/63ff59dd8a415b09. Report an issue: GitHub.