How do their APIs compare?
How do their APIs compare?
About mybatis/mybatis-3 · 2 messages · last activity 8/16/2026
Since these two projects serve very different purposes, "API comparison" mostly makes sense in terms of design philosophy and surface shape rather than feature-for-feature parity. Here's how they compare based on what's in the retrieved data:
mybatis/mybatis-3: annotation- and configuration-driven mapping API
MyBatis's public API is largely built around annotations that declare SQL bindings on interface methods, plus an underlying SQL-source/configuration layer:
- Statement annotations like
@Select,@InsertProvider,@DeleteProvider,@UpdateProvider,@SelectProviderlet you either embed SQL directly or delegate to a provider method. For example,@Selectis documented with a simple usage pattern binding a method directly to SQL [src/main/java/org/apache/ibatis/annotations/Select.java:L24-L40]. - The
*Providerannotations (InsertProvider,DeleteProvider,UpdateProvider,SelectProvider) share a consistent API pattern: atype()attribute naming a provider class, and an optionalmethod()attribute that can be omitted since 3.5.1 if the type implementsProviderMethodResolver, falling back to a conventionally namedprovideSqlmethod otherwise [src/main/java/org/apache/ibatis/annotations/InsertProvider.java:L71-L100], [src/main/java/org/apache/ibatis/annotations/SelectProvider.java:L71-L100]. This is a deliberate convention-over-configuration API design repeated across all four provider annotations. SelectProvideradditionally exposes anaffectData()flag (since 3.5.12) for statements that mutate data despite being a "select" (e.g.,RETURNING/OUTPUTclauses) [src/main/java/org/apache/ibatis/annotations/SelectProvider.java:L100-L110].- Below the annotation layer, mapping is resolved into
SqlSourceimplementations such asStaticSqlSource, which is a low-level internal API consumed by the mapper-building pipeline, not typically touched by end users directly [src/main/java/org/apache/ibatis/builder/StaticSqlSource.java:L1-L27]. - Result mapping has its own annotation API, e.g.
@Manyfor nested collection results, referencing@Result/@Results[src/main/java/org/apache/ibatis/annotations/Many.java:L24-L40].
So MyBatis's API surface is declarative and reflection/annotation-heavy, oriented around mapping Java interfaces to SQL execution, with a layered internal builder/session API underneath.
stleary/json-java: object-graph and pointer-query API
json-java's API is much smaller in conceptual scope — it's about constructing, representing, and querying JSON data structures in memory:
JSONObjectsupports bean-style reflective construction, turning getter methods into JSON keys/values, with@JSONPropertyNameto override generated key names [src/main/java/org/json/JSONObject.java:L397-L436]. This is somewhat analogous in spirit to MyBatis's annotation-driven mapping, but here it's Java-object-to-JSON rather than Java-method-to-SQL.JSONPointerimplements RFC 6901 pointer syntax, with aBuilderinner class for programmatically constructing pointers token-by-token (JSONPointer.builder().append(...).build()) [src/main/java/org/json/JSONPointer.java:L34-L73].- Both
JSONObjectandJSONArrayexpose parallelquery(String)/query(JSONPointer)(andoptQuery) methods that resolve a pointer against the structure, throwingJSONPointerExceptionon invalid paths or returningnullfor theoptvariants [src/main/java/org/json/JSONArray.java:L1583-L1622].
So json-java's API is a data-structure query/traversal API, much narrower than MyBatis's, focused on JSON parsing, construction, and pointer-based lookup rather than any persistence or SQL-binding concerns.
Key contrasts
| Aspect | mybatis-3 | json-java |
|---|---|---|
| Core abstraction | SQL statement bound to a Java method via annotations/XML | In-memory JSON tree (JSONObject/JSONArray) |
| Extension m |
Want to ask your own question?
Open chat for mybatis/mybatis-3Public Q&A. Generated by RepoPilot from the actual source of mybatis/mybatis-3. AI answers can be incomplete or stale — verify before relying on them.